Hello,
how can I paste a string1 after a particular string2 in a file?
Hi,
can you provide sample input and expected output?
can you elabrate your requirement ?
Cheers,
Ranga:)
I have a file in the form:
title1:
title2:
title3:
title4:
I want to paste the string "name" after title2. That will be:
title1
title2: name
title3
title4
sed "s/title2:/& name/" inputfile
where can i get the name, is it constant one or else it may be dynamic value ?
I assume that name is a constant one that wont get anywhere from the file.
1. sed 's/^\(title2:\)/\1 name/g' Input_File
2. awk '{if( $0 ~ /^title2:/ ){print $0,"name";}else{print $0;}}' Input_File
Cheers,
Ranga:)
Thank you all for your replies.
rangarasan, you are right, "name" is a dynamic value. In fact I have multiple 'title' files and a file with a list of 'names'. My actual code would be to read each line from the 'name' list and insert this after "title2" in each 'title' file.
okay 