Skip to main content
added 187 characters in body
Source Link
anubhava
  • 777.4k
  • 66
  • 589
  • 659

grep doesn't allow printing capture groups. Use sed:

sed -E 's/abc-([0-9]+)-zzz-([0-9]+).*/\1\2/' file

111022
222033
333044

Alternatively, if you have pcregrep then use this command to print first 2 capture groups:

pcregrep -o1 -o2 'abc-([0-9]+)-zzz-([0-9]+)' file

111022
222033
333044

grep doesn't allow printing capture groups. Use sed:

sed -E 's/abc-([0-9]+)-zzz-([0-9]+).*/\1\2/' file

111022
222033
333044

grep doesn't allow printing capture groups. Use sed:

sed -E 's/abc-([0-9]+)-zzz-([0-9]+).*/\1\2/' file

111022
222033
333044

Alternatively, if you have pcregrep then use this command to print first 2 capture groups:

pcregrep -o1 -o2 'abc-([0-9]+)-zzz-([0-9]+)' file

111022
222033
333044
Source Link
anubhava
  • 777.4k
  • 66
  • 589
  • 659

grep doesn't allow printing capture groups. Use sed:

sed -E 's/abc-([0-9]+)-zzz-([0-9]+).*/\1\2/' file

111022
222033
333044