How to use sed to print only what is matched?
If your version of grep supports it you could use the -o option to print only the portion of any line that matches your regexp. If not then here’s the best sed I could come up with: which deletes/skips with no digits and, for the remaining lines, removes all leading and trailing non-digit characters.
How to use sed to select lines in regex?
If you want to select lines then strip out the bits you don’t want: It basically selects the lines you want with egrep and then uses sed to strip off the bits before and after the number. Update: obviously if you actual situation is more complex, the REs will need to me modified.
Do you put gensub before or after regex?
Note: gensub replaces the entire regex (between the //), so you need to put the .* before and after the ( [0-9]+) to get rid of text before and after the number in the substitution. If you want to select lines then strip out the bits you don’t want:
How to print last but one field in regex SED?
This will split the input (I’m using STDIN here, but your input could easily be a file) on spaces, and then print out the last-but-one field, and then the last field. The $NF variables hold the number of fields found after exploding on spaces.
How can I print only the section that matches the regex in the group?
How can I print only the section of the line that matches the regex in the group? Match the whole line, so add a .* at the beginning of your regex. This causes the entire line to be replaced with the contents of the group grep is the right tool for extracting.
How to capture three groups of digits in SED?
So, to capture your three groups of digits, you would need to do: Use Sed with -r, –regexp-extended to avoid all escaped parenthesis. Thanks for contributing an answer to Unix & Linux Stack Exchange! Please be sure to answer the question. Provide details and share your research!
https://www.youtube.com/watch?v=QVbiyvECGZ8