linux shell: prepend or append text to next line after matching line -
using shell script in linux (bash or csh). find lines match given text pattern, , each line prepend or append (depending on application) text following line.
for example, file containing lines this:
header 1 12345 header 2 12345 header 1 12345 header 2 12345
if searching "header 1", , append text "abcde", output this:
header 1 12345 abcde header 2 12345 header 1 12345 abcde header 2 12345
i have cases want abcde preceding 12345.
i have been trying understand usage of sed purpose, feel stymied. pointers appreciated.
try command:
sed '/header 1/{n;s/$/ abcde/}' input.txt
this logic:
for each line in 'input.txt' if line matches /header 1/ read next line append string ' abcde' endif endfor
Comments
Post a Comment