Hi ,
I have one file which has many headers.
Say suppose
HEDAER
..data DATA DATA
..data
..data
HEADER
..data
..data
DATA
.data
HEADER.
..data
..data
If there are 3 HEADERS in source file then I need to split the source file into 3 separate file. And the file has some white spaces(actually its a flatfile)
So when spliiting the file I need to get the white spaces even.
Below is the script I wrote, but this does not recognise whitespaces. It wud b great if someone helps me with this.
Code is :
#!/bin/ksh -xv
publish()
{
typeset srcfile=$1
typeset splitfile=`basename $srcfile`
echo abc
echo $splitfile
typeset -i cnt=0
typeset line=""
echo $splitfile
#awk '{for(i=1;i<=NF;i++){printf("%s\n\n", $i)}}' $srcfile
#exec 3>/home/tmp/${splitfile}.part${cnt} # define our output file
cat $srcfile | while read line ; do
#awk '{for(i=1;i<=NF;i++){printf("%s\n\n", $i)}}' $srcfile
if [ $(print - "$line" | grep -c "\HEADER") -gt 0 ] ; then
# the splitter to the old output
exec 3>&- # close output
(( cnt += 1 ))
exec 3>/home/tmp/${splitfile}.part${cnt} # open the next part
print -u3 "${line##^*HEADER}" # output part of line after the
# occurence of the splitter
else # this is a regular line, just print
print -u3 "$line"
fi
done
exec 3>&- # close last output file
}
publish /home/eu_shipment_confirm.in.20090203070237
exit 0
Iam struggling for getting whiete spaces included. Can some one please respond to my query.
I am new to this forum and I dont know how to check the response. So please can some one who is assisting mail me to sanasheetal@yahoo.com
Thanks in Advance.