LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command to swap even and odd numbered lines in a file (https://www.linuxquestions.org/questions/linux-newbie-8/command-to-swap-even-and-odd-numbered-lines-in-a-file-810745/)

Vilael 05-28-2010 11:32 AM

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!

grail 05-28-2010 11:34 AM

Maybe something like this:

http://www.gnu.org/manual/gawk/html_...e_002fVariable

Vilael 05-28-2010 12:02 PM

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!


All times are GMT -5. The time now is 12:02 PM.