Delete line from file
I have two files, keep.txt and remove.txt. Both of them contain a list of files with full path like this:
/full/path/to/file/name with space1.txt
/full/path/to/file/name with space2.txt
Every line that exists in remove.txt should be removed from keep.txt. It is possible for a filename to only figure in remove.txt, and a filename can have multiple entries in keep.txt. The path can contain spaces.
I have tried with sed but I think there is a problem because the path contains unescaped /
I want to read remove.txt line by line, and check if that line also figures in keep.txt, if so delete it from keep.txt. remove.txt is no longer needed when the script finishes.
Can someone please help me?
You might want to escape the "." and other special characters that might appear in your filenames. I also assume that your filenames don't contain "|", but then the following should work:
You assumed right, the filenames don't contain "|".
But, if you have the time... Could you please explain what the IFS=$'\n' does? The rest I think I can understand.
IFS is an abbreviation of "internal field separator". We need that environment variable to deal with the space characters contained in your filenames: By default, the output of "cat remove.txt" would be split at any whitespace to form a list for the loop. But we want that output to be split only at newline characters, that's why we define IFS to contain a newline character only.
This is explained a little further at http://www.faqs.org/docs/bashman/bashref_33.html.
|All times are GMT -5. The time now is 08:52 AM.|