Sponsored Content
Full Discussion: GREP for sorting
Top Forums UNIX for Dummies Questions & Answers GREP for sorting Post 302753971 by siya@ on Wednesday 9th of January 2013 08:41:32 PM
Old 01-09-2013
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep sorting/formatting

Hi, I currently have many log files for different webpages inside the folder /log/. The program allows the user to enter a month and then the grep function searches for it, the command i used is below: grep -c "$month" ./log/*.log This works and i can ascertain the number of matches, but I... (10 Replies)
Discussion started by: Jaken
10 Replies

2. Shell Programming and Scripting

Sorting :

Hi .... iam having a file with 20,000 rows and 56 colums. Iam trying to sort a file ....for that iam using 'sort' command. If iam having 3 and 5 key colums etc ... as numerical this 'sort' command will work? what ihave to do ? sample example : E100|0|19940102|1|11111|E003... (3 Replies)
Discussion started by: satyam_sat
3 Replies

3. UNIX for Dummies Questions & Answers

Sorting using count, grep and count

Hi, I trying to sort information in a file by making count for every object. For example: A B A D A B C i would like to sort out count for each object (A's, B's and etc) but in actual case i dont know the object but i know the position ofthe object. do i need to use array as well? Any... (2 Replies)
Discussion started by: sukhpal_78
2 Replies

4. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

5. Shell Programming and Scripting

AWK/GREP sorting help

hi everyone, I am kind of new to this forum. I need help in sorting this data out accordingly, I am actually doing a traceroute application and wants my AS path displayed in front of my address like this; 192.168.1.1 AS28513 AS65534 AS5089 AS5089 .... till the last AS number and if possible sort... (8 Replies)
Discussion started by: sam127
8 Replies

6. Shell Programming and Scripting

sorting

Hii guys, I need to sort my file and remove duplicates before writing to another file. The first line in the file are column names. I dont want this line to be sorted and should always be the first line in the output. sort -u file.txt > file1.txt. is the command that i am using... (4 Replies)
Discussion started by: just4u_sharath
4 Replies

7. Homework & Coursework Questions

Shell Script: Sorting by column using grep/awk

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: You will write a script that will read a tab-separated file that contains the names of all 50 states &... (7 Replies)
Discussion started by: tburns517
7 Replies

8. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

9. Shell Programming and Scripting

Sorting

Hi, I've got two arrays 1 3 5 7 2 4 6 8 and i need to write a shell script to get the output 1 2 3 4 5 6 7 8 without using sort or bubble sort. (0 Replies)
Discussion started by: web2moha
0 Replies

10. Shell Programming and Scripting

Sorting

I do sort on the date and Time chronologically, how can I make the NIL to be below in the output Input file: KT NIL NIL ZK 02/09/2016 18:11 CD NIL NIL AS 02/09/2016 18:22 AB 02/08/2016 18:17 VA 02/09/2016 18:50 CX 02/09/2016 18:10 sort -b -k 2.9,2.10 -k 2.1,2.2 -k 2.4,2.5 -k... (3 Replies)
Discussion started by: aydj
3 Replies
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 07:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy