Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Why? | 19 comments | Create New Account
Click here to return to the 'Why?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Why?
Authored by: paploo on Mar 07, '02 06:27:32PM

A quicker way for the command line inclined is to use the command `tr':

Say you have a text file, myText.txt, and you want to translate the carriage returns to new line characters. Then boot up the terminal, cd to the proper directory, and then type:

cat myText.txt | tr "r" "n" > out.txt

Where out.txt is the name of the converted text file.

Granted, if you were doing this a lot, you should make a shell script and stick it in your ~/bin directory. I would probably make a Perl script, just because I'm more comfortable with that.

For the curious, sed could also get the job done.

-Jeff



[ Reply to This | # ]
Why?
Authored by: rbrakes on Mar 08, '02 09:34:25AM

Close, but not quite. I think the command you list above will replace all the 'r' characters with 'n' characters in the text file which is not the desired result.

Here is the command I regularly use:

tr 'r' 'n' < infile.txt > outfile.txt

The trick is to use the backslash to represent the CR and NL characters respectively.



[ Reply to This | # ]
Why?
Authored by: pmccann on Mar 08, '02 11:31:14AM

And the band played on...

This must be my cue to come in an ask if the attack of the invisible backslashes can be cured. Please! It's happening again and again. Apologies to those who have seen me whine about this already.

I dread to think what might happen if someone posts a nice command which requires a backslashed escape in a file path and someone cuts and pastes. (Sure, the user should know exactly what's being done before doing it, but bets on not everyone obeying that maxim?)

Cheers,
Paul (complete with melodrama this time...)



[ Reply to This | # ]
Why?
Authored by: TheGS on Mar 08, '02 09:11:50PM

I think you can present a backslash\ by entering it as an HTML entity (&#092;), but it might not survive the preview.



[ Reply to This | # ]