i have this data where i am looking for a two digit number 01,03,05 or 07.
if not found i should detect that .
this sed command gives me the matching rows . I want the opposite , i want the rows if the match is NOT found .
also the sed command is only looking for 01, can i add 03, 05, 07 to one command ?
its giving me all the records ?
e.g in the data below i only want the highlighted record since its 9th and 10th position DO NOT contain either 01,03,05,07
btw is it possible to just end the sed command even if one nomatching record is found ? i have a large file to search these records and its taking long time to come out .
You can use a so-called rule for this kind of tasks:
/<regexp>/ {
command1
command2
command3
....
}
will execute command1 , command2 and command3 only for lines which fit the regexp. Think of it like a "if..then..else"-construct in other languages. You can also invert it by adding an exclamation mark in front of the brackets:
/<regexp>/ ! {
command1
command2
command3
....
}
Same as above but only for lines which do NOT fit the regexp.
This way you can use the sed-command q to leave immediately when a certain line is found, Example:
/^--TheEnd--/ {
q
}
Will quit sed (and hence ignore all following lines) after the first line starting with the string "--TheEnd--" is found.
You said that you want to stop if chars 9 and 10 do not contain 0[1357] , but you include a check for eight leading digits - should that be considered essential as well? If not, try
sed -n '/^.\{8\}0[1357]/! {p;q}' file
000008070610010201NNN