• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 914
  • Last Modified:

remove carriage returns from a text file

What's a fast way to remove carriage returns from a text file so a large file can become one really long line with a space between everyword?

I tried using "J" in VI over and over but I would always get "Internal error: vredraw".  Any ideas?

Thanks.
0
jewbama
Asked:
jewbama
  • 4
  • 4
  • 2
  • +2
1 Solution
 
ozoCommented:
perl -i -pe 'BEGIN{$\=" "}chomp;' file
0
 
rbrCommented:
cat file | awk -v ORS= "{ print $1} > newfile
0
 
chris_calabreseCommented:
tr < file '
' ' ' > newfile
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
dgrimesCommented:
while read rec
do
   echo $rec"\c" >>outfile
done < inpfile
0
 
dgrimesCommented:
Found one little problem: Each new record needs to be separated by a space as well:

while read rec
do
   echo $rec" \c" >>outfile
done < inpfile

0
 
chris_calabreseCommented:
Dgrimes: the problem with this is that the shell 'read' builtin does more than just read the line into a buffer.  Rather it does all kinds of whitespace mangling and also deals with line continuation (\) processing.  The whilespace mangling may actually be a good thing for this particular application, but the line continuation probably is not.  In some shells you can get around this with 'read -r'.
0
 
dgrimesCommented:
Right, you would want to read with the -r switch. Also, not all shells support this feature. I was using ksh.

Thanks
0
 
rbrCommented:
jewbama: Did any of the comments solve your problem. If yes post to whom you give the points.
0
 
mdgreen7Commented:
I use the infozip zip and unzip utilities.

zip temp.zip filename
unzip -oa temp.zip

Or, in a pinch, you can ftp the file:

ftp localhost
login...
asc
get filename filename.new
quit
0
 
chris_calabreseCommented:
Hmm, given the suggestions above, these both seem like monumentally bad ways of doing it.
0
 
dgrimesCommented:
How does this accomplish the intended goal. However, if jewbama doesn't respond, then guess who will get the points!
0
 
mdgreen7Commented:
Oops.  My bad.  I misread the question.
I stated quick ways to convert from cr/lf to lf....

It was my first reply - I got a little anxious :)  Jeez - "monumentally bad".
0
 
chris_calabreseCommented:
Monumentally bad because it not only doesn't solve the problem, but requires a lot more effort than other suggestions already listed above that solve the problem 100%.

Don't feel bad about it, just read the comment before posting next time...
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 4
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now