The simpler way is to use only sed
:
sed '/NA/d' test >test.new
If you want to do in-place editing with GNU sed
(this will modify the file test
):
sed -i '/NA/d' test
The sed
expression /NA/d
will apply the d
command on all lines in the input that matches the regular expression NA
. The d
command deletes lines.
If the line numbers were all you had, then the following would have worked too:
some_command | sed 's/$/d/' | sed -f /dev/stdin test >output
where some_command
generates the line numbers that you'd like to delete from the file test
.
The first sed
turns the stream of numbers into a sed
script by adding a d
to each line. A line reading 100d
would be interpreted as "delete line 100". This is then fed to the second sed
as the actual script (it's reading the script via /dev/stdin
) and it is applied to the file test
.
The equivalent thing in a shell that knows about process substitutions:
sed -f <( some_command | sed 's/$/d/' ) test >output
But this is sillyness if you just want to delete lines containing the string NA
.
test
file and the final resultgrep -v 'NA' test
doesn't solve your requirement...