Print text after every ! (exclamation mark) in bash

You were almost there:

cut -d! -f2- filename | tr '!' ' '

-f2- means field 2 and all following fields

No need for cat, just work on file

tr '!' ' ' translates exclamation mark ! to space .

Or if your version of cut has an --output-delimiter= option:

cut --delimiter=! --fields=2- --output-delimiter=' ' filename

Or using awk:

awk -F! '{$1=""; print substr($0,2)}' filename
  • -F!: Sets the field delimiter to !
  • $1="": Erase first field
  • print substr($0,2): Print the whole record starting at 2nd character, since first one is blank delimiter remain from erased first field.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top