Test existence of files in shell -
Test existence of files in shell -
i have list of files , pipe command test if each files exists
cat files.txt | command
does exist command ? have write script ? can help me write ?
for example:
> cat files.txt libs/cakephp/app_exp/views/elements/export-menu.ctp libs/cron/prad_import.php main/css/admin/remarketing-graph.css main/images/dropd-arrow.png main/includes/forms/export/export_menu.php main/jquery/jquery/jquery.cookie.js main/mvc/controllers/remarketing/prad_controller.php main/mvc/controllers/remarketing/remarketing_controller.php
but of files doesn't exits, want do
> cat files.txt | command libs/cakephp/app_exp/views/elements/export-menu.ctp main/css/admin/remarketing-graph.css main/images/dropd-arrow.png main/includes/forms/export/export_menu.php main/jquery/jquery/jquery.cookie.js
that returns existing files
are using #!/bin/sh
? in context? old unix env, or in modern, stripped-down env minimal cmds?
can utilize #!/bin/bash
or #!/bin/ksh
? create easier.
but in shell should work
while read line ; if [ -f "$line" ] ; echo "$line" ; fi ; done < files.txt
this should allow file/paths spaces in them, if other odd chars embedded in filenames more work maybe required.
ihth
shell
Comments
Post a Comment