开发者

regexp to wrap a line with ${color} and $color

Is there a way to have this regex put ${color orange} at the beginning, and $color at the end of the line where the date is found?

DJS=`date +%_d`;
cat thisweek.txt | sed s/"\(^\|[^0-9]\)$DJS"'\b'/'\1${color orange}'"$DJS"'$color'/

With this expression I get this:

Saturday Aug 13 12pm - 9pm 4pm - 5pm

Sunday Aug 14 9:30am - 6pm 1pm - 2pm

Monday Aug 15 6:30pm - 11:30pm None

Tuesday Aug 16 6pm - 11pm None

Wednesday Aug 17 Not Currently Scheduled for This Day

Thursday Aug ${color orange}18$color Not Currently Scheduled for This Day

Friday Aug 19 7am - 3:30pm 10:30am - 11:30am

What I want to have is this:

Saturday Aug 13 12pm - 9pm 4pm - 5pm Sunday Aug 14 9:30am - 6pm 1pm - 2pm

Monday Aug 15 6:30pm - 11:30pm None

Tuesday Aug 16 6pm - 11pm None

Wednesday Aug 17 Not Currently Scheduled for This Day

${color orange}Thursday Aug 18 Not Currently Scheduled for This Day$color

Friday Aug 19 7am -开发者_StackOverflow 3:30pm 10:30am - 11:30am


Acually, it works for me. Depending on your version of sed, you might need to pass -r. Also, as tripleee says, don't use cat here

DJS=`date +%_d`
sed -r s/"\(^\|[^0-9]\)$DJS"'\b'/'\1${color orange}'"$DJS"'$color'/ thisweek.txt

EDIT: Ok, so with the new information I arrived at this:

sed -r "s/([^0-9]+19.+)/\${color orange}\1\$color/" thisweek.txt

This gives me the output

Saturday Aug 13 12pm - 9pm 4pm - 5pm
Sunday Aug 14 9:30am - 6pm 1pm - 2pm
Monday Aug 15 6:30pm - 11:30pm None
Tuesday Aug 16 6pm - 11pm None
Wednesday Aug 17 Not Currently Scheduled for This Day
Thursday Aug 18 Not Currently Scheduled for This Day
${color orange}Friday Aug 19 7am - 3:30pm 10:30am - 11:30am $color

(Note that it differs from your's since it's friday at least in my time zone)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜