Hi,
How can i split the big file by the lines?. For eg. I wanna split the file from the line 140 to 1700.
You only want those lines from 140 to 1700, is it ?
sed -n -e "140,1700p" bigfile.txt > newfile.txt
one more,
awk ' NR >= 140 && NR <= 1700 ' source > dest
ok, lets see how many ways we can find. Here is one in pure (Korn-)shell:
#! /bin/ksh
typeset -i iStartLine=140
typeset -i iEndLine=1700
typeset -i iLineCnt=0
typeset fSrcFile="/path/to/bigfile"
typeset fTgtFile="/path/to/file.snippet"
typeset chLineBuffer=""
exec 3>$fTgtFile
cat $fSrcFile | while read chLineBuffer ; do
(( iLineCnt += 1 ))
if [ \( $iLineCnt -ge $iStartLine \) -a \( $iLineCnt -le $iEndLine \) ] ; then
print -u3 "$chLineBuffer"
fi
done
exec 3>&-
exit 0
bakunin
or the short and simple:
head -1700 file | tail +140
Hi Madhan,
It's working fine. Thank u very much. Can I pass the variable instead of the actual number?.
(NR >= startline NR <= endline).
awk ' NR >=beg && NR <= end ' beg=2 end=5 data.txt
hope this helps.....
you can use split command in unix
awk -v start=$s end=$e ' NR >= s && NR <= e ' input > output
sed -n "${startline},${endline}p" /path/to/sourcefile > /path/to/newfile
bakunin