echo Good morning | sed 's/\(.*\s\+\).*/\1evening/g'
Here are brief notes on that ..
The above script changes Good morning
to Good evening
.
Note that the following characters needed the escape character \
:
\(
\)
\+
.
and *
characters don’t need escaping.This is the most common way of my sed usage:
echo [SOMETHING] | sed 's/old/NEW/g'
Based on that, I have this tcsh alias1 to get timestamps that I use to append to quick tar backups.
alias gettimestamp 'date | tr " :" "__" | sed '"'"'s/_[0-9]*_EDT.*//g'"'"''
Learn about sed from [here][s1].
Note how single quotes are escaped inside single-quoted alias definitions in tcsh. [s1]: http://www.grymoire.com/Unix/Sed.html ↩︎