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
S.No Array Lun
1 AABC 7080
2 AABC 7081
3 AADD 8070
4 AADD 8071
5 DDEE 1044
6 DDEE 1055
So the above is your desired output, but what does the input file look like?
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.
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.
awk 'BEGIN{ print "S No.""\t""data" } $1 ~ 21 {print ++i"\t"$0}' check_file_check12111
Output will be as follows.
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
You could also use cat -n :
$ 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