Reputation: 349
today I have this file:
a20 is (off) Jan 15
and I turned into this:
a20 is (on) Jan 16
but the second date is whatever day the a script runs
date=$(date)
with this sed commands:
sed -i '/'$1'/ s/off/on/' /home/josepas/Mantenimiento
sed -i '/'$1'/ s/).*/) /' /home/josepas/Mantenimiento
sed -i "/$1/ s/$/$date/g" /home/josepas/Mantenimiento
I want to make this a single sed that searches for the line that starts with a(somenumber) I heard about the option -e for multiple sed commands, hope you can help me
Upvotes: 0
Views: 170
Reputation: 58381
This might work for you:
date="Jan 16"
echo "a20 is (off) Jan 15" |
sed '/^a[0-9]*/s/(off).*/(on) '"$date"'/'
a20 is (on) Jan 16
if you want to use the "tomorrow date" and you're using GNU sed, then:
echo "a20 is (off) Jan 15" |
sed '/^a[0-9]\+/s/^\(.*\)(off) \(.*\)/echo "\1(on) $(date -d '\''\2 tomorrow'\'' '\''+%b %d'\'')"/e'
a20 is (on) Jan 16
Upvotes: 2
Reputation: 25736
You could concatenate s
commands with ;
and do some grouping by surrounding your commands with {
/}
. e.g.:
echo -e "a20 is (off) Jan 15\na21 is (off) Jan 15" | sed "/a20/ { s/off/on/; s/).*/) /; s/$/$(date)/ }"
Upvotes: 1