2

I am trying to remove all non-alphanumeric from a text file with the following command:

cat textfile.txt | tr -cd [:alnum:] > textfile_alnum.txt

This works, except that now the output within textfile_alnum.txt is all on the same line. How can I maintain each string on a separate line?

Shawn Mehan
  • 4,513
  • 9
  • 31
  • 51
Alkthree
  • 133
  • 2
  • 7

1 Answers1

5

If you want new lines from the original file to be preserved, use the following:

tr -cd [:alnum:]'\n'

This adds the new line character (\n) to the set of characters that you want to keep.

user12205
  • 2,684
  • 1
  • 20
  • 40