Hi,
I want to match a line which exists in a file. I have written a test script similar to below -
The content of the file file.txt would be like this -
out=`sed -n '\/usr\/bin\/7897.xcf/p' file.txt 2>&1`
echo $out ## Prints the expected line
But, my issue is that I will be getting the file contents in the code inside a variable in a while loop. i.e. like file="/usr/bin/7897.xcf". So, now, do I have to decompose this content at runtime to pass it to sed ?
Hi,
Why I need this is so that I can delete the matching line from the file. Or I should be able to replace it with a BLANK.
I saw that if I use option "d" in sed command, it echos all the lines except the given one.
`sed -n '\/usr\/bin\/7897.xcf/d' file.txt 2>&1`
So, if there is a variable, can I do the same thing with sed ? It will be lot more easier.
---------- Post updated at 11:07 PM ---------- Previous update was at 09:08 PM ----------
One solution could be -
In this example, we tell grep to look for "out dated"--with the space in the middle.
This command searches the file "myfile.new" for the text "out dated"--no matter whether upper-case or lower-case letters have been used--and puts all lines that do not have "out dated" in them into the file "myfile.newer".