GREP for sorting | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

GREP for sorting

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-09-2013
siya@ siya@ is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 19 June 2014, 11:50 PM EDT
Posts: 23
Thanks: 10
Thanked 0 Times in 0 Posts
GREP for sorting

Hi ,

I have a file which has a large number of sequences of type:


Code:
gi_1
AASSKSKSKSSKSKSK....
series_121
DDKFKFKGKGKH
gi_3
FFFFLFFLFLFLF
series_1
DFFFFFF
pattern_3
GEEEEEEEEE
gi_2
HKKGGKGKGK
series_102
HHHHH
pattern_1
HHHHH

In order to list all the sequences under gi I do
grep "gi" filename>outputfile
it gives me list of all gi .

However I want to list all of the sequences as shown below.I want to basically know the order like gi_1 followed by series_1 and by gi_3


Code:
gi_1
series_121
gi_3
series_1
pattern_3
gi_2
series_102
pattern_1


Is it possible to get all this in a single file and that too in the order they appear in file?

Should i do a multiple grep command to get all these names in a single file to get the order.


Thanks
Sia

Last edited by Scott; 01-10-2013 at 10:58 AM.. Reason: Please use code tags
Sponsored Links
    #2  
Old 01-09-2013
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 23 September 2014, 12:09 PM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
try:

Code:
grep -E "^gi_|^series_|^pattern_" input.txt

The Following User Says Thank You to rdrtx1 For This Useful Post:
siya@ (01-20-2013)
Sponsored Links
    #3  
Old 01-10-2013
glev2005 glev2005 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 19 July 2014, 10:56 PM EDT
Posts: 276
Thanks: 20
Thanked 6 Times in 6 Posts
If your example is correct, it seems that you basically want to print out everything except the uppercase lines, which could be done easily with

Code:
grep -v '^[A-Z]' filename.txt

The Following User Says Thank You to glev2005 For This Useful Post:
siya@ (01-20-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash - CLI - grep - Passing result to grep through pipe jcdole UNIX for Dummies Questions & Answers 1 04-29-2012 07:20 PM
AWK/GREP sorting help sam127 Shell Programming and Scripting 8 08-11-2010 11:05 AM
MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else hariza Shell Programming and Scripting 4 09-18-2008 03:56 AM
Sorting using count, grep and count sukhpal_78 UNIX for Dummies Questions & Answers 2 06-27-2008 01:13 AM
grep sorting/formatting Jaken Shell Programming and Scripting 10 05-13-2006 03:36 PM



All times are GMT -4. The time now is 07:00 PM.