0

I need to remove special characters from all .htm files in a directory. Ideally I need to keep the file name but if I have to I can copy each file to 1 or something like that.
Here is the command I need to run on each file: tr '\015' '\n' < $filename > $filename.1

migrated from serverfault.com Jun 28 '14 at 19:09

This question came from our site for system and network administrators.

  • Where is the problem? Apparently you know what you need to run. – NeplatnyUdaj Jun 27 '14 at 14:08
  • I don't know how to do the for loop or the xargs to run that command on every file in directory ... and I don't know how to run that command and keep the same file name – xivix Jun 27 '14 at 14:09
  • In bash: for file in /dir/* do your command done – NeplatnyUdaj Jun 27 '14 at 14:12
  • it doesn't work ... I get ambiguous redirect error – xivix Jun 27 '14 at 14:16
  • and if I try this ls *.htm | xargs -i tr '\015' '\n' < {} > {}_1 then I get back: -bash: {}: No such file or directory – xivix Jun 27 '14 at 14:28
1

I don't know what OS and interpreter you use, but this works for me on Debian/Bash:

for file in *.htm; do
  tr "\044" "\n" < $file > $file.1;
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy