Reputation: 2725
I want to delete all the rows/lines in a file that has a specific character, '?' in my case. I hope there is a single line command in Bash or AWK or Perl. Thanks
Upvotes: 3
Views: 11784
Reputation: 63952
Here are already grep, sed and perl solutions - only for fun, pure bash one:
pattern='?'
while read line
do
[[ "$line" =~ "$pattern" ]] || echo "$line"
done
translated
=~
||
- print out the lineUpvotes: 2
Reputation: 45672
Even better, just a single line using sed
sed '/?/d' input
use -i
to edit file in place.
Upvotes: 6
Reputation: 274738
You can use sed
to modify the file "in-place":
sed -i "/?/d" file
Alternatively, use grep:
grep -v "?" file > newfile.txt
Upvotes: 9