Reputation: 87
It might sound a weird request and I totally understand that this is not the purpose of regex. I am just looking for a possible workaround or a feature that is less used / documented (if any)
The scenario is I can provide a regex as an admin for configuring an option where a file / web service response is parsed for matches and same is returned to end user; (Application and other details don't seem to be important but if you are interested please let me know.)
Now is it possible that I specify a string in the pattern that is not considered from matching but is returned with the match. like
[String :] [regex pattern]
and now the regex engine ignores the [string] and for matches returns
[String : match1] [String : match2] [String : match3] ...
Upvotes: 2
Views: 838
Reputation: 7610
If you want to have a suffix added to all the lines matched with a regex then you can try something like the following,
The following command adds the string "STRING" to all the matched lines,
grep -w "Your_Pattern" Your_FILE | sed -e 's/^/STRING/'
Upvotes: 1