LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-31-2008, 04:44 PM   #1
Turkeyboy
LQ Newbie
 
Registered: Dec 2008
Posts: 1

Rep: Reputation: 0
I Need to merge 2 lines in a text file into 1


Hi all, can you please help me?
I have a text file with some data in it. I need to merge every second line with the one above. For example

25-12-08
10.5
26-12-08
10.6
27-12-08
10.7

Would become

25-12-08 10.5
26-12-08 10.6
27-12-08 10.7

I guess this is pretty easy to do but am a but new to Linux. All help Appreciated!

Cheers!
 
Old 12-31-2008, 05:00 PM   #2
truth believer
LQ Newbie
 
Registered: Dec 2008
Location: Tehran, Iran
Distribution: Mandriva - DSL
Posts: 17

Rep: Reputation: 1
It seems you know how to edit a text in a text editor like Windows Notepad but you don't know how to open your file in a text editor.
If it is a linux distribution like mine you can right-click on the file, then choose "Open With", then choose "Text Editor" or "Gedit" or "Vim" or "Emacs". All of them and many else are text editors.

If it doesn't work, give us more data about your linux distribution(version) or the situation your on.
 
Old 12-31-2008, 05:11 PM   #3
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
A script like
Code:
#!/bin/sh
#

while read odd
do
        read even
        echo $odd $even
done < "infile"
where infile contains the input data will do it.
 
Old 12-31-2008, 05:32 PM   #4
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
Code:
cat file | xargs -n2
Replace red with your actual file.

This will also produce the same result as the script above.
 
Old 12-31-2008, 05:37 PM   #5
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
I thought there'd be a simpler way.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:11 PM
Merge lines from a file lourencojunior Linux - Newbie 5 05-12-2008 02:54 PM
Grab text lines in text file LULUSNATCH Programming 1 12-02-2005 11:55 AM
adding text to lines in a file tpreitano Linux - General 2 10-04-2005 10:30 AM
merge multiple lines of a single file into one line groverrajiv Linux - Newbie 4 05-26-2004 03:38 AM


All times are GMT -5. The time now is 09:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration