sorting based on alternative lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sorting based on alternative lines
# 1  
Old 08-23-2011
sorting based on alternative lines

Hello,

I have a file with multiple entries.

Code:
@SFGF-GA2-1_58:5:36:11009:999#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
+SFGF-GA2-1_58:5:36:11009:999#0/1
################################################################################
@SFGF-GA2-1_58:5:36:14498:999#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
+SFGF-GA2-1_58:5:36:14498:999#0/1
################################################################################
@SFGF-GA2-1_58:5:36:3395:1010#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

I just want lines that start with @SFGF and the following line after it.

o/p

Code:
@SFGF-GA2-1_58:5:36:11009:1110#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
@SFGF-GA2-1_58:5:36:14498:999#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
@SFGF-GA2-1_58:5:36:14498:999#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
@SFGF-GA2-1_58:5:36:3395:1010#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

after this the file should be sorted based on @SFGF line.

o/p
Code:
@SFGF-GA2-1_58:5:36:14498:999#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
@SFGF-GA2-1_58:5:36:14498:999#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
@SFGF-GA2-1_58:5:36:3395:1010#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
@SFGF-GA2-1_58:5:36:11009:1110#0/1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

Thanks,
# 2  
Old 08-23-2011
Code:
 sed -n '/^@SFGF/{N;p;}' Inp_File

# 3  
Old 08-23-2011
Could you fill in some of that NNNNN stuff? We need to see where you want it to end up too. And that line of ##### disappears mysteriously.
# 4  
Old 08-23-2011
Code:
awk '/^@SFGF/{print;getline;print}' file

What is the sort key for this data?
# 5  
Old 08-23-2011
first file

Code:
@SFGF-GA2-1_58:5:36:11009:999#0/1
ATGCATGCATGCATGCATAGGCATAGATAGACAGATACAGATATAGACATAGACATAGAAATATAT
+SFGF-GA2-1_58:5:36:11009:999#0/1
################################################################################
@SFGF-GA2-1_58:5:36:14498:1110#0/1
ATGGCGCTTTGCGTGGGCGTTTGACGAAGTTTGGGACCAGGGATAGCAGAAAATTTGACATAGACAT
+SFGF-GA2-1_58:5:36:14498:999#0/1
################################################################################
@SFGF-GA2-1_58:5:36:3395:1010#0/1
ATGCATGCCCCGTTTTAAACCGTTTGAAATTGCDCATGGATTTAGGGACCCATTGACCCATTACAATA
+SFGF-GA2-1_58:5:36:3395:1010#0/1
################################################################################

o/p

second file
[CODE]@SFGF-GA2-1_58:5:36:11009:999#0/1
ATGCATGCATGCATGCATAGGCATAGATAGACAGATACAGATATAGACATAGACATAGAAATATAT
@SFGF-GA2-1_58:5:36:14498:1110#0/1
ATGGCGCTTTGCGTGGGCGTTTGACGAAGTTTGGGACCAGGGATAGCAGAAAATTTGACATAGACAT
@SFGF-GA2-1_58:5:36:3395:1010#0/1
ATGCATGCCCCGTTTTAAACCGTTTGAAATTGCDCATGGATTTAGGGACCCATTGACCCATTACAATA

second o/p

Code:
@SFGF-GA2-1_58:5:36:11009:999#0/1
ATGCATGCATGCATGCATAGGCATAGATAGACAGATACAGATATAGACATAGACATAGAAATATAT
@SFGF-GA2-1_58:5:36:3395:1010#0/1
ATGCATGCCCCGTTTTAAACCGTTTGAAATTGCDCATGGATTTAGGGACCCATTGACCCATTACAATA
@SFGF-GA2-1_58:5:36:14498:1110#0/1
ATGGCGCTTTGCGTGGGCGTTTGACGAAGTTTGGGACCAGGGATAGCAGAAAATTTGACATAGACAT

# 6  
Old 08-23-2011
Try:
Code:
perl -ln0e '$,="\n";print sort {(split /:|#/, $a)[4]<=>(split /:|#/, $b)[4]} /^\@SFGF.*\n.*/mg;' file

# 7  
Old 08-23-2011
Thanks for the reply.

Its throwing an error

"panic: pp_match start/end pointers at -e line 1, <> chunk 1."

is it perl -lne?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting based on File name

Hi All I have a requirement to list all the files in chronological order based on the date value in the file name.For ex if I have three files as given below ABC_TEST_20160103_1012.txt ABC_TEST_20160229_1112.txt ABC_TEST_20160229_1112.txt I have written code as given below to list out... (2 Replies)
Discussion started by: ginrkf
2 Replies

2. Shell Programming and Scripting

Sorting based on filename

Hello , I have to write a bash script. I will explain the logic based on a scenario. Scenario : Suppose I have few files in a Folder X : FILE_201508.list FILE_201510.list FILE_201507.list abc_201510.csv xyz_201508.csv abc_201507.csv def_201507.csv 1) Now ,... (3 Replies)
Discussion started by: smamrm
3 Replies

3. Shell Programming and Scripting

Sorting block of lines based on specified strings

Below is the part of contents of a file cat outputFile.txt :APP-MS-service_monitoring-118054-DiskFilling-S Description=Disk is getting filled. If Condition=If Event/Log Level(ANY) and matching substring &quot;DiskFilling&quot; Log: xx.x.x..xx.: 4 days 1:33:54.42 Date and time=03-18-2013... (2 Replies)
Discussion started by: vivek d r
2 Replies

4. Shell Programming and Scripting

Sorting based on the second field

Oracle Enterprise Linux 6 This is my file. Two fields separated by space $ cat testfile.txt MARCH9 MARCH4 MARCH1 MARCH5 MARCH2 MARCH326 MARCH821 MARCH7 MARCH6 MARCH2 $ $ The following numeric sort, based on the first field's 6th character works as expected. $ $ sort -n -k 1.6... (7 Replies)
Discussion started by: John K
7 Replies

5. Shell Programming and Scripting

Sorting file based on name

Hi team, We have few files landing to our server based on sequence number. These files have to be processed in the sequence number order. Once the sequence number has reached its maximum, the files with sequence number 0000 has to be processed. For example: IN9997 IN9998 IN9999 IN0000... (7 Replies)
Discussion started by: anijan
7 Replies

6. Shell Programming and Scripting

Sorting based on a particular colum

Hi, I want a flat file(pipe delimited) to be sorted based on 2nd column only. Below is input file to be sorted. AVERS|K50034|A|Y|N|N|Y|Y|Y|||N|N AVERS|K50035|A|Y|N|N|Y|Y|Y|||N|N... (11 Replies)
Discussion started by: Nikhath
11 Replies

7. Shell Programming and Scripting

sorting based on a field

the below is sorted as it is. the fields that i'm interested in are the 4th and 5th field. i want to sort the based on the 4th field. my past attempt to do this was to do something like this: awk '{print $4}'| awk '{print $1":"$2}' datafile | sort | uniq however, if i do that, i lose... (2 Replies)
Discussion started by: SkySmart
2 Replies

8. Shell Programming and Scripting

Sorting lines based on keywords for MySQL script

the thing which i require is very very complex.. i tried hard to find the solution but couldnt.. the thing i need to achieve is say i have a file cat delta.sql CREATE VIEW Austin Etc etc . . . CREATE VIEW Barabara AS SELECT blah blah blah FROM Austin z, Cluster s, Instance i WHERE... (4 Replies)
Discussion started by: vivek d r
4 Replies

9. UNIX for Advanced & Expert Users

Alternative needed for joining lines with a match

Hi, The following sed command is not working for me, does anyone have a good alternative for joining lines in a file based on a match? # if a line ends with a backslash, append the next line to it sed -e :a -e '/\\$/N; s/\\\n//; ta' (6 Replies)
Discussion started by: greptastic
6 Replies

10. Shell Programming and Scripting

Sorting based on columns

Hi, I want a list of entries in 3 space delimited columns. I want to sort entries based on the very first column. Rows can't be changed. For example: If I have... Abc Abc Acc Bca Bda Bdd Cab Cab Cbc Dbc Dca Dda Abc Abc Acc the output should be... Abc Abc Acc Abc Abc Acc Bca... (7 Replies)
Discussion started by: MobileUser
7 Replies
Login or Register to Ask a Question