9

File,

.false alarm is bla no. 11
.no alarm generated is bla
.application will be killed is bla wall command
.doc file is document file with .doc extension
.no authority for this selection bla

Now what I want in my output file to print the lines which contains only the word bla (Or it may be number also)

Output will be like this,

1 .false alarm is bla no. 11
2 .no alarm generated is bla
3 .application will be killed is bla wall command
5 .no authority for this selection bla
  • awk 'i++ {if($1~/RRBS/) print i}' ../../bak/bak.db – Shicheng Guo May 13 '17 at 23:44
18

Many tools can be handy:

  • -n of grep is exactly what you are looking for.

    grep -n 'bla' file
    
  • alternatively awk:

    awk '/bla/{print NR":"$0}' file
    
  • alternatively perl:

    perl -ne 'print $.,":",$_ if /bla/' file
    
  • alternatively sed:

    sed '/bla/!d;=' file |sed 'N;s/\n/:/'
    
  • :-) yes... got the desired output. @jimmij – pmaipmui Aug 25 '15 at 19:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.