Need sequence no in the grep output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need sequence no in the grep output
# 1  
Old 01-15-2014
Need sequence no in the grep output

Hi,

How to achieve the displaying of sequence no while doing grep for an output.

Ex., need the output like below with the serial no, but not the available line number in the file

Code:
S.No  Array   Lun 
1       AABC  7080
2       AABC  7081
3       AADD  8070
4       AADD  8071
5       DDEE  1044
6       DDEE  1055

# 2  
Old 01-15-2014
So the above is your desired output, but what does the input file look like?
# 3  
Old 01-15-2014
Hello,

Assuming that you want to search a particular pattern and then you want to count the particular search sequences. Here is the example for same.

Code:
Input file:
$ cat check_file_check12111
col1   col2      col3        col4   col5        col6      col7
21     66745     rs1234      21     rs5678      23334     0.89
21     66745     rs2334      21     rs9978      23334     0.89
23     66745     rs3334      21     rs7578      23334     0.89
24     66745     rs6664      21     rs9998      23334     0.89
21     66745     rs8884      21     rs5588      23334     0.89

Code to get the requested output will be.


Code:
awk 'BEGIN{ print "S No.""\t""data" } $1 ~ 21 {print ++i"\t"$0}' check_file_check12111

Output will be as follows.


Code:
S No.   data
1       21     66745     rs1234      21     rs5678      23334     0.89
2       21     66745     rs2334      21     rs9978      23334     0.89
3       21     66745     rs8884      21     rs5588      23334     0.89


This is just an example there are sevral ways to grep the patterns, please be more specific in your requirement to get the exact Output.



Thanks,
R. Singh
# 4  
Old 01-16-2014
You could also use cat -n :

Code:
$ grep "^21" check_file_check121111 | cat -n
     1  21     66745     rs1234      21     rs5678      23334     0.89
     2  21     66745     rs2334      21     rs9978      23334     0.89
     3  21     66745     rs8884      21     rs5588      23334     0.89

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to have the output in grep?

Hi guys - I am trying to have a certain file display information horizontally divided by a pipe. for example file name: foo.dat has information like this: name1 name2 name3 namenamename4 namene5 I would like it to display like this: name1|name2|name3|namenamename4|namene5 ... (6 Replies)
Discussion started by: DallasT
6 Replies

2. Shell Programming and Scripting

Grep regex to ignore sequence only if surrounded by fwd-slashes

Hi, I've got a regex match to perform in a Bash script and can't quite get it right. Basically I want to match all IP address like sequences in a file which may or may not contain an IP address but with the extra qualification of ignoring any IP-like sequence which begins and ends with a... (27 Replies)
Discussion started by: gencon
27 Replies

3. Shell Programming and Scripting

How to grep the desired output and output to a file?

currently I have process from a raw file to this stage ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID") ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID") ALTER TABLE... (10 Replies)
Discussion started by: jediwannabe
10 Replies

4. Red Hat

Grep doesn't understand escape sequence?

I ran the following grep and sed command. grep "\t" emp.txt sed -n '/\t/p' emp.txt grep treated the '\' as to escape t and took the pattern as literal t whereas sed took the pattern as tab. That means , grep doesn't understand escape sequence!!!!!! what to do to make grep... (8 Replies)
Discussion started by: ravisingh
8 Replies

5. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

6. Shell Programming and Scripting

grep output

hi i am running grep -c on a bunch of files some of which may be non existent. The output i get is in the same order as the files grep checks and this is what i want as i need to copy the output to a spreadsheet. However when i tried to pipe the output to sed to strip away the filenames and just... (5 Replies)
Discussion started by: chronics
5 Replies

7. Shell Programming and Scripting

grep output

From below mentioned line,i have to display output as last word only ie:arch_1_105366_720809746.dbf -rw-r----- 1 oracle dba 98887680 02 Mar 12:01 arch_1_105366_720809746.dbf Please .. (5 Replies)
Discussion started by: Sanal
5 Replies

8. UNIX for Dummies Questions & Answers

Help with grep output

Hello, I have a list of stings that I'm using with grep to determine which files contain the strings. Here's what I have now: list of strings in a file (list.txt): /directory/direc tory/file.jsp /dire ctory/directory/direct ory/file.jsp grep I'm doing to find files that contain the... (4 Replies)
Discussion started by: upstate_boy
4 Replies

9. Shell Programming and Scripting

To grep in sequence

Hi, I have a log file containg records in sequence <CRMSUB:MSIN=2200380,BSNBC=TELEPHON-7553&TS21-7716553&TS22-7716553,NDC=70,MSCAT=ORDINSUB,SUBRES=ONAOFPLM,ACCSUB=BSS,NUMTYP=SINGLE; <ENTROPRSERV:MSIN=226380,OPRSERV=OCSI-PPSMOC-ACT-DACT&TCSI-PPSMTC-ACT-DACT&UCSI-USSD;... (17 Replies)
Discussion started by: helplineinc
17 Replies

10. Shell Programming and Scripting

output of grep

hi, why the following is giving entire /etc/passwd file as output even when it does not contain ^ or $ . grep ' ' /etc/passwd whereas the following is not giving any output grep ' ^$ ' /etc/passwd (3 Replies)
Discussion started by: useless79
3 Replies
Login or Register to Ask a Question