grep a pattern with line numbers.

I have a txt file with more than 10000 lines. There is a unique pattern which is scattered into the file. it starts with @9 and it has 15 characters. i need to grep them and display along with line numbers.

Eg: File - Test1

test message....
....
..
..
@9qwerty89
...test message @9qwerty56......
....end

Output should be as:

5: @9qwerty89
6: @9qwerty56

Can somebody help me in getting this.

Is this fine..? Else post the inputfile with some more contents..

grep -in '^@9' inputfile > outfile

How about this

$ cat Test1
test message....
.... @9qwertyNO skip this
..
..
@9qwerty8992081 more
...test message @9qwerty56l2dkv rest message @9Perty056l2dkv rest
....end
 
$ grep -Enow '\@9[[:alnum:]]{13}' Test1
5:@9qwerty8992081
6:@9qwerty56l2dkv
6:@9Perty056l2dkv

"@" is an ordinary character in both posix regular expression flavors, basic and extended. According to the standard, in extended regular expressions, preceding an ordinary character with a backslash always yields an undefined result (in basic regular expressions, there are a few defined backslash-ordinary character sequences but none of them involved "@"). It's probably best to ditch "\@" in favor of an unescaped "@".

More info @ Regular Expressions

Regards,
Alister

Sample file:

3628234::10120234236:042302134 SVP[3301]:: GE SupplychainInfomationBox::MART_LOOKING::value=@9querty34,day=Tues;
3628244::12342344444:042342344 SVP[3302]:: GE SupplychainInfomationBox::MART_LOOKING::value=@9querfy34,day=tend;
3345803::24555101206::243042304 SvP[3306]: SF SysPositionCar:DInfom::set kes_@9quefwe56-type_METHOD=null
2253245::10122432306::043442253 PLX[3301]: DC EManagersImplg:DsInform::soSuper-ult: search://mnt/var/docs/The%20set%20and%20unset-type_@9querwy91-shel_meth-w_1.wer
23434284::10120232336::233042253 EDK[3401]: SDRT Run:DISC NAME:put type=@9querwy91,

Here "@9" and followed by 8 digits are to be grepped and displayed along with the line numbers.

Eg output:

1:@9querty34
2:@9querfy34
3:@9quefwe56
4:@9querwy91
5:@9querwy91

Please let me know if i am not clear.

sed -r 's/(.*)(@9.*[0-9][0-9])([^0-9].*)/\2/' file
@9querty34
@9querfy34
@9quefwe56
@9querwy91
@9querwy91

Just drop the word match in grep:

grep -Eno '@9[[:alnum:]]{8}' infile

or if your grep does not know "-o" try this:

awk -F'[^@[:alnum:]]*' '{for(i=1;i<=NF;i++)if($i~/^@9........$/)print NR":",$i}' infile

Awesome. this is working as expected. Great Thanks.

 $ ruby -lne 'print "#{$.} #{$_.scan(/@9\w{1,8}/)[0]}" if /@9/' file