Skip to main content
2 of 2
Thank you @Terdon
Chris Davies
  • 128.2k
  • 16
  • 179
  • 324

The starting point for this could be a simple loop:

while IFS= read -r item
do
    [ -f "$item" ] && printf '%s\n' "$item"
done <file.txt

This could be crashed onto a single line at the expense of readability:

while IFS= read -r item; do [ -f "$item" ] && printf '%s\n' "$item"; done <file.txt

Or you could use Perl:

perl -lne 'print if -f' file.txt
Chris Davies
  • 128.2k
  • 16
  • 179
  • 324