I have to extract data from a text file which is huge in size >>10GB.
ie between two strings. If I do an ordinary sed it takes forever to come out. I was wondering if there was anyway to do the entire process in reverse and on finding the relevant string is there any way to break out of the search..
reading a file in reverse,
# !/usr/bin/ksh
linecnt=`wc -l file | awk '{print $1}'`
while [ $linecnt -ge 1 ]
do
sed -n "$linecnt"p file
linecnt=$(($linecnt - 1))
done
exit 0
thanks man!!
Just for info: If you have GNU coreutils installed, you'll find the tac utility (reversed cat :rolleyes: ) does the job of reading a file from bottom to top. But this won't find your match and break out for you
Cheers
ZB
1 Like
From "HANDY ONE-LINERS FOR SED" ...
# reverse order of lines (emulates "tac")
sed '1!G;h;$!d' # method 1
sed -n '1!G;h;$p' # method 2
Similiar replies to a similiar post - sort a file in reverse order. I wonder how many use the search feature of the forum.