Sponsored Content
Top Forums Shell Programming and Scripting How to swap order of pairs of lines? Post 302488085 by rd5817 on Friday 14th of January 2011 10:13:12 PM
Old 01-14-2011
MySQL 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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

reading lines in pairs from file in ksh

I need to read pairs of lines from a file and compare them. We can assume that the number of lines in the file is even. Can i do it in korn shell? (4 Replies)
Discussion started by: ytokar
4 Replies

2. Shell Programming and Scripting

How to grep lines in the particular order?

Hi guys, I am stuck on a simple issue but couldn't find a simple solution. If you have any ideas please help. I have two files : - FILE1 Tue 09/12 Lindsey Wed 09/13 Randy Thu 09/14 Susan Fri 09/15 Randy Sat 09/16 Lindsey Sun ... (2 Replies)
Discussion started by: sam_2921
2 Replies

3. Shell Programming and Scripting

Order file by lines

My script(3 arguments $1 = folder,$2 extension,$3 string) should do the following things: -Enter in the folder of $1(if exists). -Put ls *.$2 > temp.txt ( I use a temp file to store the result of ls command and if $2 = txt in this file I'll have all the .txt files of the folder) -Now I want to... (2 Replies)
Discussion started by: Max89
2 Replies

4. Shell Programming and Scripting

concatenate lines in pairs

Hi, I have a text file with the following contents /C=IT/O=INFN/OU=Personal Certificate/L=Napoli/CN=Some guy /C=IT/O=INFN/CN=INFN CA /O=Grid/O=NorduGrid/OU=uninett.no/CN=Another guy /O=Grid/O=NorduGrid/CN=NorduGrid Certification Authority /C=TW/O=AP/OU=GRID/CN=Someone else... (5 Replies)
Discussion started by: kerl
5 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. Shell Programming and Scripting

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. ... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

7. 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

8. UNIX for Advanced & Expert Users

Parse (delimited string) key-value pairs in a column into separate lines

Hi experts, e.g. i/p data looks like 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747,9700005405717924,9700005405733788|unidentified,unidentified,unidentified|| o/p data should like - row1: 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747|unidentified ... (1 Reply)
Discussion started by: sumoka
1 Replies

9. Shell Programming and Scripting

File w/ many line pairs--how do I order based on 1st lines only?

I have a file in which the data is stored in pairs of lines. The first line (beginining with ">") is a header, the second line is a sequence. I would like to sort the file by species name. Desired output for the example file: I can use sort -t'_' -k2 to alphabetize headers in the... (1 Reply)
Discussion started by: pathunkathunk
1 Replies

10. Shell Programming and Scripting

Remove lines with duplicate pairs where AB is equal to BA

I have a file with four columns like dmn10003t1 PF00001 PF00022 dmn12390t1 dmn10008t1 PF00069 PF00027 dmn9781t1 dmn10008t1 PF00068 PF00027 dmn9781t1 dmn10008t1 PF00069 PF00069 dmn9781t1 dmn12390t1 PF00069 PF00076 dmn10003t1 I want to create a new file by comparing the repeated word pairs... (2 Replies)
Discussion started by: sammy777
2 Replies
GREP(1) 						      General Commands Manual							   GREP(1)

NAME
grep - search a file for a pattern SYNOPSIS
grep [ option ... ] pattern [ file ... ] DESCRIPTION
Grep searches the input files (standard input default) for lines (with newlines excluded) that match the pattern, a regular expression as defined in regexp(6). Normally, each line matching the pattern is `selected', and each selected line is copied to the standard output. The options are -c Print only a count of matching lines. -h Do not print file name tags (headers) with output lines. -i Ignore alphabetic case distinctions. The implementation folds into lower case all letters in the pattern and input before interpre- tation. Matched lines are printed in their original form. -l (ell) Print the names of files with selected lines; don't print the lines. -L Print the names of files with no selected lines; the converse of -l. -n Mark each printed line with its line number counted in its file. -s Produce no output, but return status. -v Reverse: print lines that do not match the pattern. Output lines are tagged by file name when there is more than one input file. (To force this tagging, include /dev/null as a file name argument.) Care should be taken when using the shell metacharacters $*[^|()= and newline in pattern; it is safest to enclose the entire expression in single quotes '...'. SOURCE
/sys/src/cmd/grep.c SEE ALSO
ed(1), awk(1), sed(1), sam(1), regexp(6) DIAGNOSTICS
Exit status is null if any lines are selected, or non-null when no lines are selected or an error occurs. GREP(1)
All times are GMT -4. The time now is 10:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy