You are not logged in.
Pages: 1
I need to insert some characters after a line that contains a certain word. Let's say my text file contains something like:
this
is
about
shell
programming
how can I insert the word "advanced" so it would be between about and shell, resulting in a text file that looks like
this
is
about
advanced
shell
programming
I'm not interested in a method that will insert advanced using the number of the proper line, I need to know how can I insert a word, on a new line referring to another string of characters.
Thanks for your time
Last edited by I'mGeorge (2011-06-17 05:27:33)
I've first installed Arch in March
Offline
Use sed. Add the -i flag to edit "in place" or just redirect output to a new file.
$ cat file
this
is
about
shell
programming
$ sed '/^about$/aadvanced' file
this
is
about
advanced
shell
programming
$ sed '/^about$/iadvanced' file
this
is
advanced
about
shell
programming
Offline
You can replace the word of interest with itself, a newline, and the inserted word.
< TEXT sed 's/about/about\nadvanced/'
Offline
thanks a bunch, this is exactly what I was looking for
I've first installed Arch in March
Offline
Pages: 1