I have a list contains filenames. Some of filenames contain whitespaces:
./folder/folder/some file name.ext
I need to grep each of these files:
cat filelist | while read i; do grep "pattern" $i; done
Obviously grep fails because of whitespaces:
grep ./folder/folder/some: No such file or directory
grep file: No such file or directory
grep name: No such file or directory
I've tried to escape whitespaces like:
:%s/some file name/some\ file\ name/g
but no luck. How can I perform my operation? Thanks!
You can use this loop:
while read -r i; do grep "pattern" "$i"; done < filelist
Using a pipe with cat is error prone and BASH will treat strings with space as separate arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With