For example , A text file has:
dfsdfsd
f
dsf
dsf
dsf
dsf
sdafadfdasfdsfd
sf
sdfasdfdasfdsfsdf
sd
fsdfdsaf
Then , i would like to find a way to obtain the line number of sf
and insert a paragraph before sf
Are there any ways to doing it in bash programming ???thanks
If you want to find out the line number, you could use
grep -n.If you just want to insert a line on the preceding line, you could use
sedlike this:This will insert the text “paragraph” above the line with “sd”.
To only do this for the first match:
Here, we only match lines until the first matching “sd”, so any later sd’s will not match.