SED command to comment all the lines except the one's that matched the pattern
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have the below cron.txt
file
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
And I need to comment (add #
) at the beginning of all the lines that doesn't have pattern CXC
or HP
in it.
I tried
grep -iwvE "CXC|HP" cron.txt | sed 's/^/#/g' > cron.txt_bkp
It didn't work as expected.
text-processing sed grep hp-ux
add a comment |Â
up vote
1
down vote
favorite
I have the below cron.txt
file
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
And I need to comment (add #
) at the beginning of all the lines that doesn't have pattern CXC
or HP
in it.
I tried
grep -iwvE "CXC|HP" cron.txt | sed 's/^/#/g' > cron.txt_bkp
It didn't work as expected.
text-processing sed grep hp-ux
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have the below cron.txt
file
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
And I need to comment (add #
) at the beginning of all the lines that doesn't have pattern CXC
or HP
in it.
I tried
grep -iwvE "CXC|HP" cron.txt | sed 's/^/#/g' > cron.txt_bkp
It didn't work as expected.
text-processing sed grep hp-ux
I have the below cron.txt
file
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
And I need to comment (add #
) at the beginning of all the lines that doesn't have pattern CXC
or HP
in it.
I tried
grep -iwvE "CXC|HP" cron.txt | sed 's/^/#/g' > cron.txt_bkp
It didn't work as expected.
text-processing sed grep hp-ux
edited Jan 30 at 9:58
Kusalananda
103k13202318
103k13202318
asked Jan 30 at 5:34
sabarish jackson
119111
119111
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
4
down vote
Assuming that your implementation of grep
supports both the -w
and the -E
flag, your grep
and sed
pipeline would only extract and comment out the lines that didn't contain HP
or CXC
. The lines that were to be left as-is will not be transferred to the new file.
Since HP-UX sed
seems to not support alteration with |
in regular expressions, which means that /CXC|HP/!s/^/# /
won't work, you may apply something like this to the file:
sed -e '/CXC/b' -e '/HP/b' -e 's/^/# /' crontab.txt >crontab-new.txt
The b
command makes sed
branch to the end of the editing script if the pattern is found on the current line. It acts as a "print line and continue with next line" command here.
If neither of the first two expressions are acted upon, then the line is commented out by the last expression.
The file crontab-new.txt
, created above, will hold the following contents given the example in the question:
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
# 00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
1
I think you misread the question. You got it backwards.
â Wildcard
Jan 30 at 7:39
@Wildcard Now properly corrected.
â Kusalananda
Jan 30 at 8:47
add a comment |Â
up vote
1
down vote
A solution with awk:
awk '!/CXC|HP/$0="#" $01' cron.txt > cron.txt_bkp
1
gsub()
could be changed tosub()
. There is only one single match of^
in a line... Alternatively, into just$0 = "#" $0
.
â Kusalananda
Jan 30 at 10:57
add a comment |Â
up vote
0
down vote
I have used below sed command to achieve the same
cron.txt
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
command
sed '/HP/!s/^/#/g' cron.txt | sed '/CXC/s/^#//g' >cron.txt_bkp
output
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
#00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
This will definitely work, but it's a tiny bit roundabout way of doing it (adding, then removing comments).
â Kusalananda
Jan 31 at 9:13
Kindly vote for my answer
â Praveen Kumar BS
Jan 31 at 9:52
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
Assuming that your implementation of grep
supports both the -w
and the -E
flag, your grep
and sed
pipeline would only extract and comment out the lines that didn't contain HP
or CXC
. The lines that were to be left as-is will not be transferred to the new file.
Since HP-UX sed
seems to not support alteration with |
in regular expressions, which means that /CXC|HP/!s/^/# /
won't work, you may apply something like this to the file:
sed -e '/CXC/b' -e '/HP/b' -e 's/^/# /' crontab.txt >crontab-new.txt
The b
command makes sed
branch to the end of the editing script if the pattern is found on the current line. It acts as a "print line and continue with next line" command here.
If neither of the first two expressions are acted upon, then the line is commented out by the last expression.
The file crontab-new.txt
, created above, will hold the following contents given the example in the question:
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
# 00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
1
I think you misread the question. You got it backwards.
â Wildcard
Jan 30 at 7:39
@Wildcard Now properly corrected.
â Kusalananda
Jan 30 at 8:47
add a comment |Â
up vote
4
down vote
Assuming that your implementation of grep
supports both the -w
and the -E
flag, your grep
and sed
pipeline would only extract and comment out the lines that didn't contain HP
or CXC
. The lines that were to be left as-is will not be transferred to the new file.
Since HP-UX sed
seems to not support alteration with |
in regular expressions, which means that /CXC|HP/!s/^/# /
won't work, you may apply something like this to the file:
sed -e '/CXC/b' -e '/HP/b' -e 's/^/# /' crontab.txt >crontab-new.txt
The b
command makes sed
branch to the end of the editing script if the pattern is found on the current line. It acts as a "print line and continue with next line" command here.
If neither of the first two expressions are acted upon, then the line is commented out by the last expression.
The file crontab-new.txt
, created above, will hold the following contents given the example in the question:
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
# 00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
1
I think you misread the question. You got it backwards.
â Wildcard
Jan 30 at 7:39
@Wildcard Now properly corrected.
â Kusalananda
Jan 30 at 8:47
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Assuming that your implementation of grep
supports both the -w
and the -E
flag, your grep
and sed
pipeline would only extract and comment out the lines that didn't contain HP
or CXC
. The lines that were to be left as-is will not be transferred to the new file.
Since HP-UX sed
seems to not support alteration with |
in regular expressions, which means that /CXC|HP/!s/^/# /
won't work, you may apply something like this to the file:
sed -e '/CXC/b' -e '/HP/b' -e 's/^/# /' crontab.txt >crontab-new.txt
The b
command makes sed
branch to the end of the editing script if the pattern is found on the current line. It acts as a "print line and continue with next line" command here.
If neither of the first two expressions are acted upon, then the line is commented out by the last expression.
The file crontab-new.txt
, created above, will hold the following contents given the example in the question:
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
# 00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
Assuming that your implementation of grep
supports both the -w
and the -E
flag, your grep
and sed
pipeline would only extract and comment out the lines that didn't contain HP
or CXC
. The lines that were to be left as-is will not be transferred to the new file.
Since HP-UX sed
seems to not support alteration with |
in regular expressions, which means that /CXC|HP/!s/^/# /
won't work, you may apply something like this to the file:
sed -e '/CXC/b' -e '/HP/b' -e 's/^/# /' crontab.txt >crontab-new.txt
The b
command makes sed
branch to the end of the editing script if the pattern is found on the current line. It acts as a "print line and continue with next line" command here.
If neither of the first two expressions are acted upon, then the line is commented out by the last expression.
The file crontab-new.txt
, created above, will hold the following contents given the example in the question:
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
# 00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
# 01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
edited Jan 30 at 10:55
answered Jan 30 at 7:37
Kusalananda
103k13202318
103k13202318
1
I think you misread the question. You got it backwards.
â Wildcard
Jan 30 at 7:39
@Wildcard Now properly corrected.
â Kusalananda
Jan 30 at 8:47
add a comment |Â
1
I think you misread the question. You got it backwards.
â Wildcard
Jan 30 at 7:39
@Wildcard Now properly corrected.
â Kusalananda
Jan 30 at 8:47
1
1
I think you misread the question. You got it backwards.
â Wildcard
Jan 30 at 7:39
I think you misread the question. You got it backwards.
â Wildcard
Jan 30 at 7:39
@Wildcard Now properly corrected.
â Kusalananda
Jan 30 at 8:47
@Wildcard Now properly corrected.
â Kusalananda
Jan 30 at 8:47
add a comment |Â
up vote
1
down vote
A solution with awk:
awk '!/CXC|HP/$0="#" $01' cron.txt > cron.txt_bkp
1
gsub()
could be changed tosub()
. There is only one single match of^
in a line... Alternatively, into just$0 = "#" $0
.
â Kusalananda
Jan 30 at 10:57
add a comment |Â
up vote
1
down vote
A solution with awk:
awk '!/CXC|HP/$0="#" $01' cron.txt > cron.txt_bkp
1
gsub()
could be changed tosub()
. There is only one single match of^
in a line... Alternatively, into just$0 = "#" $0
.
â Kusalananda
Jan 30 at 10:57
add a comment |Â
up vote
1
down vote
up vote
1
down vote
A solution with awk:
awk '!/CXC|HP/$0="#" $01' cron.txt > cron.txt_bkp
A solution with awk:
awk '!/CXC|HP/$0="#" $01' cron.txt > cron.txt_bkp
edited Jan 30 at 12:46
answered Jan 30 at 5:53
Isaac
6,7021734
6,7021734
1
gsub()
could be changed tosub()
. There is only one single match of^
in a line... Alternatively, into just$0 = "#" $0
.
â Kusalananda
Jan 30 at 10:57
add a comment |Â
1
gsub()
could be changed tosub()
. There is only one single match of^
in a line... Alternatively, into just$0 = "#" $0
.
â Kusalananda
Jan 30 at 10:57
1
1
gsub()
could be changed to sub()
. There is only one single match of ^
in a line... Alternatively, into just $0 = "#" $0
.â Kusalananda
Jan 30 at 10:57
gsub()
could be changed to sub()
. There is only one single match of ^
in a line... Alternatively, into just $0 = "#" $0
.â Kusalananda
Jan 30 at 10:57
add a comment |Â
up vote
0
down vote
I have used below sed command to achieve the same
cron.txt
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
command
sed '/HP/!s/^/#/g' cron.txt | sed '/CXC/s/^#//g' >cron.txt_bkp
output
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
#00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
This will definitely work, but it's a tiny bit roundabout way of doing it (adding, then removing comments).
â Kusalananda
Jan 31 at 9:13
Kindly vote for my answer
â Praveen Kumar BS
Jan 31 at 9:52
add a comment |Â
up vote
0
down vote
I have used below sed command to achieve the same
cron.txt
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
command
sed '/HP/!s/^/#/g' cron.txt | sed '/CXC/s/^#//g' >cron.txt_bkp
output
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
#00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
This will definitely work, but it's a tiny bit roundabout way of doing it (adding, then removing comments).
â Kusalananda
Jan 31 at 9:13
Kindly vote for my answer
â Praveen Kumar BS
Jan 31 at 9:52
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I have used below sed command to achieve the same
cron.txt
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
command
sed '/HP/!s/^/#/g' cron.txt | sed '/CXC/s/^#//g' >cron.txt_bkp
output
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
#00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
I have used below sed command to achieve the same
cron.txt
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
command
sed '/HP/!s/^/#/g' cron.txt | sed '/CXC/s/^#//g' >cron.txt_bkp
output
58 18 * * 1-5 /usr/home/script.sh REP CXC BS TODAY all 1>/dev/null 2>/dev/null
#00 19 * * 1-5 /usr/home/script.sh DSC DXC BUS TODAY all 1>/dev/null 2>/dev/null
01 19 * * 1-5 /usr/home/script.sh REP HP SNT TODAY all 1>/dev/null 2>/dev/null
03 19 * * 1-5 /usr/home/script.sh DSC CXC SNT TODAY all 1>/dev/null 2>/dev/null
32 10 * * 1-5 /usr/home/script.sh Check CXC OD TODAY MGLA 1>/dev/null 2>/dev/null
32 12 * * 1-5 /usr/home/script.sh Sca CXC OD TODAY all "01 03 05 07 08 10 12 17 18 19 31 32 33 37 42 50 53 55 57 84 89 93" 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP HK SNT TODAY all 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP RAM SNT TODAY all 1>/dev/null 2>/dev/null
#01 19 * * 1-5 /usr/home/script.sh REP SAB SNT TODAY all 1>/dev/null 2>/dev/null
answered Jan 30 at 17:52
Praveen Kumar BS
1,010128
1,010128
This will definitely work, but it's a tiny bit roundabout way of doing it (adding, then removing comments).
â Kusalananda
Jan 31 at 9:13
Kindly vote for my answer
â Praveen Kumar BS
Jan 31 at 9:52
add a comment |Â
This will definitely work, but it's a tiny bit roundabout way of doing it (adding, then removing comments).
â Kusalananda
Jan 31 at 9:13
Kindly vote for my answer
â Praveen Kumar BS
Jan 31 at 9:52
This will definitely work, but it's a tiny bit roundabout way of doing it (adding, then removing comments).
â Kusalananda
Jan 31 at 9:13
This will definitely work, but it's a tiny bit roundabout way of doing it (adding, then removing comments).
â Kusalananda
Jan 31 at 9:13
Kindly vote for my answer
â Praveen Kumar BS
Jan 31 at 9:52
Kindly vote for my answer
â Praveen Kumar BS
Jan 31 at 9:52
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420586%2fsed-command-to-comment-all-the-lines-except-the-ones-that-matched-the-pattern%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password