I want to delete a specific line of a file in bash.
What I am currently doing is to get the line number and pass it so sed
to delete this line:
awk '/qr/{ print NR; exit }' test | sed -i "${1}d" test
The awk
part works well, but in this state, the sed
part deletes all the content of the file (named test).
However, when I do it without the variable :
sed -i '1d' test
It works fine.
What am I doing wrong ?
awk
, as inawk '/qr/{if (!i++) next}1' test
(assuming you only want to remove the first occurence)? If you need "inplace" function, GNUawk
> 4.1.0 supports the-i inplace
command-line option for that. – AdminBee May 25 '20 at 08:45