LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-24-2004, 05:37 AM   #1
groverrajiv
LQ Newbie
 
Registered: Apr 2004
Location: INDIA
Posts: 2

Rep: Reputation: 0
merge multiple lines of a single file into one line


Dear

I would like to merge two or more line of a single file into one line, can some body help me

Rajiv
 
Old 04-24-2004, 06:52 AM   #2
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
it depends on how the line is terminated.
you can look at it with cat -A <file>
unix text will end with $
dos text will end with ^M$

tr '\012\015' '' < filenamefrom > filenameto

will remove carriage return newline from a dos text file


edit: i think that should have been

tr -d '\012\015' < filenamefrom > filenameto

Last edited by whansard; 05-26-2004 at 02:40 AM.
 
Old 04-24-2004, 06:04 PM   #3
jeremy
root
 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,602

Rep: Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083
Moved: This thread is more suitable in Linux - Newbie and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 05-25-2004, 06:34 PM   #4
guest
Member
 
Registered: May 2003
Distribution: CentOS 5 64 bit
Posts: 255

Rep: Reputation: 30
Unix

What about for Unix?

What I cat -a FILE I get a $ at the end of the line.

Thanks,

-a
 
Old 05-26-2004, 02:38 AM   #5
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
do you just want to remove the newline, or do you want it replaced with a space character?

tr -d '\012' < infile > outfile
removes it
tr '\012' ' ' <infile>outfile
replaces with a space

looks like i made a mistake in my answer above.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge lines in a file using sed arobic Programming 8 01-20-2012 02:11 PM
How To Merge multiple files into a single PDF ? kkempter Linux - Software 1 10-28-2005 01:02 PM
Retrieve only a single line from a file rose_bud4201 Programming 4 06-22-2005 06:26 PM
Using diff to compare file with common lines, but at different line numbers jimieee Linux - Newbie 3 05-10-2004 07:26 AM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 01:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration