-1

I've got the following code:

cd /home/pi/.attract/romlists; for file in *.tag ; do grep -v -F 'Arcade Snooker [AGA]' $file > $file1.tmp && mv -f $file1.tmp $file; done

This works well to remove the fixed string "Arcade Snooker [AGA]" from a file such as "Amiga.tag". However, it does not remove the string from "Atari 800.tag" or from any other file that has a "space" in its name. The result for "Atari 800.tag" is the following error:

grep: Atari: No such file or directory
grep: 800.tag: No such file or directory

What changes do I need to make to the code please to get it to remove "Arcade Snooker [AGA]" from "Atari 800.tag" and from other such files containing spaces in their names?

I would prefer to have one line of code only please as I have it now.

Thanks.

Spud
  • 73
  • 5
  • [for name in `ls` and filenames with spaces](https://stackoverflow.com/q/8645546/608639) – jww Jan 04 '19 at 03:43
  • I don't know why you downvoted my question. The response you have provided does not fix my code. The answer I upvoted fixes the code and does so on one line as I asked. – Spud Jan 07 '19 at 12:43

1 Answers1

3

You need to quote the variables if the file names contain spaces...

cd /home/pi/.attract/romlists; for file in *.tag ; do grep -v -F 'Arcade Snooker [AGA]' "$file" > "$file1.tmp" && mv -f "$file1.tmp" "$file"; done
tink
  • 14,342
  • 4
  • 46
  • 50