LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 05-28-2010, 11:32 AM   #1
Vilael
LQ Newbie
 
Registered: May 2010
Distribution: LFS
Posts: 2

Rep: Reputation: 0
Question Command to swap even and odd numbered lines in a file


G'day Gang!

I'm looking for a command to swap the even/odd numbered lines in a file.

Example input file:
Code:
1
2
3
4
5
6
7
8
9
10
Example output file:
Code:
2
1
4
3
6
5
8
7
10
9
I'm sure there's a way to do it with sed, awk, grep and the like but it's been many years since I've used these commands on a daily basis and I can't seem to figure out the correct syntax.

Any help would be greatly appreciated. Thanks!
 
Old 05-28-2010, 11:34 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,527

Rep: Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896
Maybe something like this:

http://www.gnu.org/manual/gawk/html_...e_002fVariable
 
1 members found this post helpful.
Old 05-28-2010, 12:02 PM   #3
Vilael
LQ Newbie
 
Registered: May 2010
Distribution: LFS
Posts: 2

Original Poster
Rep: Reputation: 0
LOL. I swear to you I have hunted for days banging my head on that. I knew it would be super simple, which I why I was reluctant to ask about it.

Thanks very much!
 
  


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
deleting even numbered lines bharatbsharma Programming 7 11-26-2007 05:34 AM
Random file lines directed to a new file. In script an error. In command line no err leventis Programming 1 09-28-2006 07:16 AM
Remove odd lines from a text file Mr. Gone Programming 2 09-19-2005 11:16 AM
command to count how many lines in a file? dr_zayus69 Linux - Software 3 01-06-2005 10:42 AM
use file data in command lines karlis Linux - General 3 08-29-2003 07:27 PM

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

All times are GMT -5. The time now is 08:03 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