-1

How can I a command at the beginning of every line example -

My file contains following text -

abc
efg
hij

So I want to add this sed -n '/^<<</,/^>>>/p' i.e.

sed -n '/^<<</,/^>>>/p' abc
sed -n '/^<<</,/^>>>/p' efg
sed -n '/^<<</,/^>>>/p' hij

I tried to run this command

sed -i 's/^/sed -n '/^<<</,/^>>>/p'' test.txt but it did not work.

Can someone help here ?

Arnold
  • 31
  • 5

1 Answers1

0

You can use awk for that:

$ cat test 
abc
def
ghi
$ awk '{print "sed -n \x27/^<</,/^>>/p\x27 " $0}' test
sed -n '/^<</,/^>>/p' abc
sed -n '/^<</,/^>>/p' def
sed -n '/^<</,/^>>/p' ghi

I am pretty sure that using ' in print can be done with better style then \x27, but I do not have a good idea for that right now.

Szczerba
  • 271
  • 1
  • 8
  • Thanks @Szczerba this works good but I will go with sed -i "s#^#sed \-n \'/\<\<\\\,/\^\>\>\>/p\' #" test.txt which User123 recommended as this would save me a step of creating a new file. – Arnold Oct 04 '18 at 18:51