Entradas

Mostrando entradas de 2018

Unix notes - sed command

Imagen
https://www.tecmint.com/linux-sed-command-tips-tricks/ cat input.txt | sed "s|[[:print:]][[:space:]]date| $varchar_10|Ig" > output.txt varchar_10='varchar(10)' cat input.txt | sed "s/\bdate\b/$varchar_10/Ig" > output.txt

Replace patterns in a file

#!/bin/bash # February 3th, 2018 # Create a table copy in the same database # shPid=$$ inputSqlFile=statement.sql tmp=".sql.${shPid}" newInputSqlFile=statement_$shPid.sql pattern="alter table" target_tableName="tmp.people_copy" source_tableName="tb01.people" input_tablespace="ss" tablespaceName="in $input_tablespace" if [ -z "$input_tablespace" ] ; then     tablespaceName="" fi rTarget_table="target_table" rSourve_table="source_table" rTablespace="in_tablespace" echo "$inputSqlFile" sed "/$pattern/Q" $inputSqlFile > $tmp cp $inputSqlFile $tmp sed "s/${rTarget_table}/${target_tableName}/" $tmp > $newInputSqlFile sed "s/${rSourve_table}/${source_tableName}/" $newInputSqlFile > $tmp sed "s/${rTablespace}/${tablespaceName}/" $tmp > $newInputSqlFile cat $newInputSqlFile rm $tmp rm $newInputSqlFile ----------------------

Sed: Extract a file's part with sed command

#!/bin/bash # February 3rd, 2018 export Me=$(basename $0 .sh) export fecha_actual=`date "+%Y-%m-%d_%H%M%S"` inputFile=notas.txt pattern="find" # cut the file here echo "$inputFile" # q: show the file until the pattern, including it. # Q: show the file until the pattern, NOT including it. sed "/$pattern/Q" $inputFile