I have a file of filenames for files in a certain directory. However, some of the file names may:
- Have spaces in the original filename replaced with underscores (so
directory/file with spaces
becomesfile_with_spaces
in the input file) - May not actually match a file in the directory
If I didn't have these two conditions, I'd use cat inputfile | awk 'commands'
to process apply the commands I want on the file. However, I would like for some way to catch filename not found errors and either:
- Try with different combinations of underscores being replaced with spaces until it finds a matching file
- Provide a list of files that had no matches, even after substituting spaces for underscores.
Is there a good way to do this? I suspect that some type of script will be needed (rather than a one-line command), but I am not yet familiar with shell scripting enough to think of the solution.
inputfile
which is a list of filenames, one per line. However these names might not be exact, in particular filenames with spaces in them might be listed with underscores, but maybe not every space has been changed to underscore. You want to get the real names of the files that are listed, and also any values which are in theinputfile
but doesn't have a matching real file. Is this a fair summary?inputfile
. All spaces in the original filenames have been converted to underscores, but not every underscore was originally a space. I want the real filenames so I can run a different command over them and the subset of non-matching names for manual investigation.actualnames
and one forno-matches
, then run my command overactualnames
and useno-matches
as my to-do list. What I need the help with would be turninginputfile
into those two lists.a_b
anda b
. If there were, it should match both, but if it makes things simpler, there aren't any files with names that are similar in that manner.