Grep and print only the corresponding word and the following words

I have a text file, install.history

Wed June 20 23:16:32 CDT 2014, EndPatch, FW_6.0.0, SUCCESS

I would need to print a word starting from EndPatchto the end, which is the FW_6.0.0, SUCCESS
command below, which I print only EndPatch, so I need to make it print the remaining words so that my result is as follows:

EndPatch, FW_6.0.0, SUCCESS

Here is the command I have:

  grep -oh "EndPatch[[:alpha:]]*" 'install.history'
+4
source share
4 answers

This might be easier to do with sed:

sed -n 's/.*EndPatch, //p' install.history

to get the word after EndPatch:

sed -n 's/.*EndPatch, \([^,]*\).*/\1/p' install.history

or

sed -n 's/.*EndPatch, //p' install.history | cut -d, -f
+3
source

You can try the following grep command to get everything from EndPatchto the last,

grep -oP 'EndPatch, (.*)$' file

or

grep -o 'EndPatch.*$' file

Example:

$ grep -oP 'EndPatch, (.*)$' file
EndPatch, FW_6.0.0, SUCCESS
$ grep -o 'EndPatch.*$' file
EndPatch, FW_6.0.0, SUCCESS

or

, , EndPatch,

$ grep -oP 'EndPatch, \K(.*)$' file
FW_6.0.0, SUCCESS
+1

You need grep -efor regular expression matching

grep -oh 'install.history' -e "EndPatch[[:alpha:]]*"
0
source

you can use awk

awk -F "EndPatch, " '{print FS$2}' file
EndPatch, FW_6.0.0, SUCCESS
0
source

Source: https://habr.com/ru/post/1545787/


All Articles