Reputation: 925
I have a file that named tmp
that contains 4 strings:
dirs
f1
f2
f3
I want to stay with
f1
f2
f3
What bash command helps me to accomplish this? (Only bash please, no sed or awk.)
Upvotes: 0
Views: 203
Reputation: 231
regular expression with grep: either
grep 'f' tmp > name_of_output_file
or
grep '[^"dirs"]' tmp > name_of_output_file
work for me
Upvotes: 0
Reputation: 22821
You could use:
grep -v "dirs" tmp
The -v
argument of grep
will negate the match, i.e. it will exclude anything matching dirs
from the file tmp
Or if you wanted a pure bash
solution:
while read -r line
do
if ! [[ $line =~ "dirs" ]]
then
echo $line
fi
done < tmp
Upvotes: 2