sed - append text after match from multiple file locations -


am noob when comes coding bear me... trying write script input data 3 separate files 3 specific locations within text file - example: edited read easier

#start of script start_of_line1_text "$1" end_of_line1_text start_of_line2_text "$2" end_of_line2_text start_of_line3_text "$3" end_of_line3_text #output text when done     $1 value in text1 $2 value in text2 $3 value in text3 

i thinking of using sed cant quite work out how done...

or insert word @ $1 after matching random_text? ie:

sed '/start_of_line1_text/ middle_of_line1_text' input 

also on larger scale - if text1,2 , 3 had multiple values in how import these values 1 @ time , save new file each time? example:

text1 =  b c  text2 =  e f g  text3 =  h j   #start of script start_of_line1_text "line 1 of text1" end_of_line1_text start_of_line2_text "line 1 of text2" end_of_line2_text start_of_line3_text "line 1 of text3" end_of_line3_text #output text when done    

then:

#start of script start_of_line1_text "line 2 of text1" end_of_line1_text start_of_line2_text "line 2 of text2" end_of_line2_text start_of_line3_text "line 2 of text3" end_of_line3_text #output text when done    

im not fussy on language used bit stuck how fit together....

many in advance

this problem suits awk.

give try:

awk '!f[fnr] {f[fnr]=("out" fnr ".txt"); print "#start of script" >f[fnr]} {print "random_text \"" $0 "\" some_other_text" >f[fnr]} end {for(n in f) print "#output text when done">f[n]}' text1 text2 text3 

the output files generated in current directory out1.txt , out2.txt etc.

you can provide number of text files input @ end of command.

there below script file version additional parameters:

#!/usr/bin/awk -f !f[fnr] {   f[fnr]=("out" fnr ".txt")   print first >f[fnr] } {    print start $0 end >f[fnr] } end {   for(n in f) print last>f[n] } 

the test:

chmod +x ./script.awk ./script.awk -v first="#start of script"                          \              -v start="random_text \"" -v end="\" some_other_text"\              -v last="#output text when done"                  \              text1 text2 text3 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -