bilroth
2012-12-03 21:43:41 UTC
I would like to remove all contiguous matching the regex:
"[0-9][0-9].[0-9][0-9].[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] na$" or
"[0-9][0-9].[0-9][0-9].[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] na na
$" or
"[0-9][0-9].[0-9][0-9].[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] na na
na$" or
"[0-9][0-9].[0-9][0-9].[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] na na
na na$"
occurring at the end of a file (if any). Each file will only contain
lines with one of these patterns, but I would like something generic that
will work for any of the files I have. I want to leave all lines
matching this pattern at the start or in the middle of the file (i.e.
surround by other lines) untouched. Obviously if a file contains only
lines matching the regex then the command should produce an empty file.
Ideally I would like to do this with sed, and while it is very straight
forward to remove all occurrences in the file with sed, but I cant
workout out how to restrict to just the lines at the end.
Can this be done with sed. The next obvious way I can see of doing this
is reversing the file with tac, using a read loop to count the number of
lines matching the pattern. Subtract this from the total number of lines
in the file (calculated using wc). Passing the file through tac again
and then using head to extract the lines I want. This seems rather
convoluted and I have struggle to write the loop to count the correct
number of lines.
Any help would be appreciated.
"[0-9][0-9].[0-9][0-9].[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] na$" or
"[0-9][0-9].[0-9][0-9].[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] na na
$" or
"[0-9][0-9].[0-9][0-9].[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] na na
na$" or
"[0-9][0-9].[0-9][0-9].[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] na na
na na$"
occurring at the end of a file (if any). Each file will only contain
lines with one of these patterns, but I would like something generic that
will work for any of the files I have. I want to leave all lines
matching this pattern at the start or in the middle of the file (i.e.
surround by other lines) untouched. Obviously if a file contains only
lines matching the regex then the command should produce an empty file.
Ideally I would like to do this with sed, and while it is very straight
forward to remove all occurrences in the file with sed, but I cant
workout out how to restrict to just the lines at the end.
Can this be done with sed. The next obvious way I can see of doing this
is reversing the file with tac, using a read loop to count the number of
lines matching the pattern. Subtract this from the total number of lines
in the file (calculated using wc). Passing the file through tac again
and then using head to extract the lines I want. This seems rather
convoluted and I have struggle to write the loop to count the correct
number of lines.
Any help would be appreciated.