BASH: Swap first two lines in sets of 4


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH: Swap first two lines in sets of 4
# 1  
Old 09-18-2011
BASH: Swap first two lines in sets of 4

Hi.

I may have mentioned in the OP to this thread that the AHK macro script I was trying to sort was, relative to its full length, only partly in the right format to be sorted by the methods discussed in that thread.

Now I'm looking to tackle the rest of the data in that AHK script.

Example data:
Code:
::god::
;Great Outdoors
Send, Great Outdoors,
Exit

::sand::
;On The Beaches
Send, On The Beaches,
Exit

::budapest::
;Hungarian Honeys
Send, Hungarian Honeys,
Exit

::ukgirl::
;British Birds & Belles
Send, British Birds & Belles, 
Exit

::fool::
;Getting Goofy::
Send, Getting Goofy,
Exit

I did the first one by hand (actually by using some awk commands in terminal) to show what I mean by "swap."
Code:
;Great Outdoors
::god::
Send, Great Outdoors,
Exit

Now I'm looking to automate the process for the rest of the data that's formatted as the above. In my C&P from the original AHK file, I count 45 such "quatrains" (4-line sets of data). I may have missed some in cutting and pasting.

Though the subject line of this OP says "BASH," I am, of course, not partial to it. Perl solutions are also welcome.

BZT
# 2  
Old 09-18-2011
Code:
awk -F'\n' '{
  print $2, $1, $3, $4
  }' OFS='\n' RS= ORS='\n\n' infile

This User Gave Thanks to radoulov For This Post:
# 3  
Old 09-18-2011
Quote:
Originally Posted by radoulov
Code:
awk -F'\n' '{
  print $2, $1, $3, $4
  }' OFS='\n' RS= ORS='\n\n' infile

Works. TYVM. BZT
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Explain the output of swap -s and swap -l

Hi Solaris Folks :), I need to calculate the swap usage on solaris server, please let me understand the output of below swap -s and swap -l commands. $swap -s total: 1774912k bytes allocated + 240616k reserved = 2015528k used, 14542512k available $swap -l swapfile dev swaplo... (6 Replies)
Discussion started by: seenuvasan1985
6 Replies

2. Shell Programming and Scripting

Search and swap multiple lines in file using Perl

Hi all, I have a vcd file with a bunch of lines containing an array, like this $var wire 1 b a $end $var wire 1 c a $end $var wire 1 d a $end $var wire 1 e a $end $var wire 1 f b $end $var wire 1 g b $end $var wire 1 h b $end $var wire 1 i b $end I want it like this: $var wire 1 e a... (12 Replies)
Discussion started by: veerabahu
12 Replies

3. Shell Programming and Scripting

sed swap lines

Hi, I think it is possible with sed, but I'm not sure... I've a file that contains some text and filenames: gtk-media-pause | CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip | 8175 | /home/floris/Muziek/Karaoke/1341838939/CB60471-05 - Gilbert, Brantley - Country Must Be... (2 Replies)
Discussion started by: jkfloris
2 Replies

4. Shell Programming and Scripting

How to swap order of pairs of lines?

This seems to be a question whose answer uses sed or awk. For a file like: a b c d e How to swap the order of the line pairs, to end up with: b a d c e All lines from the original file need to wind up in the output file. (8 Replies)
Discussion started by: rd5817
8 Replies

5. UNIX for Advanced & Expert Users

Swap lines using sed

Hi, I have to swap two consecutive line using sed in a file. My text to swap is available in the file x.pl #Create & map a common work library if (!(-e "../work")) { system ("vlib work ../work"); system ("vmap work ../work"); } system ("vsimsa -do thiagu_dec.do"); In this i... (6 Replies)
Discussion started by: adharmalingam
6 Replies

6. HP-UX

Swap device file and swap sapce

Hi I have an integrity machine rx7620 and rx8640 running hp-ux 11.31. I'm planning to fine tune the system: - I would like to know when does the memory swap space spill over to the device swap space? - And how much % of memory swap utilization should be specified (swap space device... (6 Replies)
Discussion started by: lamoul
6 Replies

7. Solaris

Swap config - Mirror swap or not?

Hello and thanks in advance. I have a Sun box with raid 1 on the O/S disks using solaris svm. I want to unmirror my swap partition, and add the slice on the second disk as an additional swap device. This would give me twice as much swap space. I have been warned not to do this by some... (3 Replies)
Discussion started by: BG_JrAdmin
3 Replies

8. Shell Programming and Scripting

Inserting Lines between data sets using SED?

Hello all and thanks in advance! What I'm looking to do is insert a blank line, anytime the first 9 characters of a given line don't match the first 9 characters of the previous line. i.e. Convert the data set 1 45 64 89 1 89 69 235 2 89 234 67 2 56 90... (1 Reply)
Discussion started by: selkirk
1 Replies

9. Virtualization and Cloud Computing

Clouds (Partially Order Sets) - Streams (Linearly Ordered Sets) - Part 2

timbass Sat, 28 Jul 2007 10:07:53 +0000 Originally posted in Yahoo! CEP-Interest Here is my follow-up note on posets (partially ordered sets) and tosets (totally or linearly ordered sets) as background set theory for event processing, and in particular CEP and ESP. In my last note, we... (0 Replies)
Discussion started by: Linux Bot
0 Replies
Login or Register to Ask a Question

Featured Tech Videos