有沒有辦法讓這個正則表達式在開始處放置$ {color orange},並在找到該日期的行的末尾放置$ color?
DJS=`date +%_d`;
cat thisweek.txt | sed s/"\(^\|[^0-9]\)$DJS"'\b'/'\1${color orange}'"$DJS"'$color'/
有了這個表達我得到這個:
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
我想擁有的是:
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 - 3:30pm 10:30am - 11:30am
你基本上有釘;如果這對你不起作用,我懷疑這是因爲不兼容的正則表達式構造 - 我不認爲我已經看到了例如'grod \ b'的'sed'。此外,失去無用的貓。 – tripleee
重新編輯:啊。那麼,從原來的措辭來看,這不太容易知道;)我會更新我的答案 – carlpett