i want to transform this:
# blah # gen = 0 1 1 1 1 1 1 # gen = 1 2 2 2 2 2 2 # gen = 2 3 3 3 3 3 3 . . . # gen = 10 10 10 10
in to this :
# blah # gen = 0 1 1 1 1 1 1 # gen = 1 2 2 2 2 2 2 # gen = 2 3 3 3 3 3 3 . . . # gen = 10 10 10 10
that is i want to introduce one or more new line before all lines starting with “# gen = “. this is how one can do it using sed.
sed 's/^# gen.*/\n\n&/' <a.out >b.out
- ‘s/ bit :: is for the substitute command
- ^# gen :: is the regular expression which matches all lines starting with a # followed by gen
- .* :: matches everything else on the lines starting with a # followed by gen
- \n\n :: will introduce 2 blank lines
- & :: simply stands for the matched part that is, it stands for everything matched by ^# gen.*
- a.out :: input file the file i want to transform
- b.out :: is the required file..the file i want to have
i wish i could do the same thing sitting in emacs.
In emacs, you can do
M-x query-replace-regexp
# gen
C-q C-j \&
many thanks 🙂