I wish to delete lines from a log file. Should take a date string as a variable. Find the date in the file, get the line number for the string. Delete lines from 1 to that (line number - 1), all from within a shell script. Is that possible ?.
Thnks,

I wish to delete lines from a log file. Should take a date string as a variable. Find the date in the file, get the line number for the string. Delete lines from 1 to that (line number - 1), all from within a shell script. Is that possible ?.
Thnks,

umal,
Yes you can. Use sed, cat and grep then you shou,d be able to do that or sed and awk.
line=`grep -n "${datevariable}" log_filename|cut -d":" -f1`
sed "1,${line} d" log_filename
I tried this out , sed "1,${line} d" log_filename
This leaves the log_filename as it is. I would have to
sed "1,${line} d" log_filename > log_filename.new
mv log_filename log_filename.old
mv log_filename.new log_filename
the log file is constantly being written to, so how can I guarantee there wont be any loss of data...
I wish to delete lines from the log as with "vi". Besides wont inodes change ?
ruby -i -ne 'BEGIN{S=ARGV.shift}
f=true if $_.index(S);print if f' "Dec 13" myfile
What does ruby mean ?
i dont have idea bt ruby
but as far as maintaining the same file inode, try this
perl -pie "s/.....
the idea here is to use perl with flags -pie, doubt if you have perl installed.
I have posted this solution of perl -pie on numerous occassions where a temp file creation is to be omitted.
you can find it in some searches.