system
June 14, 2007, 2:54am
1
I am working on a file with specific timestamps.
I want to delete all the lines above the timestamp 18:31. I tried using the following command but it deleted 18:31 also.
sed '1,/18:[0-9][0-9]/d' <file-name>
Some quick help will be appreciated !!!!!!
anbu23
June 14, 2007, 3:15am
2
sed -e '1,/18:/d' -e'/18:/d' filename
system
June 14, 2007, 3:19am
3
thanks for the reply but it deleted the timestamp starting with 18:, i want to retain all the timestamp starting with 18:
anbu23
June 14, 2007, 3:22am
4
I didn't read your requirement properly.
Try this
sed -n '/18:/,$ p' filename
system
June 14, 2007, 3:39am
5
Thanks a lot. I am not that good with regex
anbu, this is something that's I've been looking to do for awhile but couldnt find a simple way to do it.
Can you please explain what that command is doing so I can fit it to my needs?
sed -n '/18:/,$ p' filename
-n --> Displays only those lines specified by the "p" command.
/18:/,$ --> Range of lines from pattern "18:" to end of file "$".
p --> Print
awk '/18:/{ flag=1; }
{
if (flag) { print }
}' "file"
Fisrt find the line above which should be deleted, then use sed to delete all
the desired lines.
As follow,(newer in unix,pls try:p)
num=`awk '{
if($3=="18:01")
n=NR;
}
END{
print n;
}' filename`
num=`expr $num - 1`
sed "1,${num}d" filename