Monday, November 10, 2014

Using Bash and Sed for Quick String Manipulations

To print the first string starting with an _  :

$ tmp="ffuts erom dna erom _this and _that _is here ___okay"

## Mark the first string for extraction, then use sed to grab it and remove the marker
$ echo "${tmp2/ _/ XXX_}" | sed 's/.*\(.*XXX[^ ]*\).*/\1/;s/XXX//'

No comments:

Post a Comment