Search a file

Need assistance in getting some tips or ideas .

-xfile.txt has a scripts with path . I have a directory which has all the scripts -how can i use awk or grep to see the scripts in xfile.txt that match files in the directory . Your help is highly appreciated.

xfile.txt

/home/demo/script/abc.sh
/home/demo/fc/scripts/hello.sh
/home/gear/scripts/test.sh
/home/scripts/demo.sh

Dir

abc.sh
def.sh
demo.sh
foo.sh
bar.sh

The below command can give the result but I want the opposite way .

grep abc.sh xfile.txt

opposite way which it will not work .

grep /home/demo/script/abc.sh
 DIR
while read file
do
  if [ -f "${file}" ]; then
     echo "${file}"
  fi
done < xfile.txt
1 Like

How about

ls $(awk -F\/ '{print $NF}' xfile.txt)
1 Like