0

I have a long report in the form of text tab-delimnated ( meaning if I open this text file in excel spreadsheet then every word and number will fit in a cell). In this report there are key words that I am looking for and I want to print the four numbers next to this key word. For example, let's say this paragraph is in the report (which is text tab delimnated) and the key word is "number "

The following number 00 02 25 226 is my card ID.

I can use the command "grep" to search for the exact word "number", but how can I grep this word and the next four cells (i.e. digits)

0
grep -Eo 'number( [0-9]+)+' input
  • Thank you for the help. I guess [0-9] means how many words grep will output following the key word. Right? If so, when I changed [0-9] to [0-2] I got "number 00 02 2". I mean it must output "number 00 02 25" Any suggestions are highly appreciated! – user88036 May 11 '17 at 23:17
  • [0-9] means any character of 0123456789. [0-9]+ means "one or more such character". – DopeGhoti May 11 '17 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy