awk inside shell and script aborting

Hi
I have a requirement where i need to convert the xml in various lines into a single line and then split the file so that the file contains only 1000 records each.

searching this forum, i found a command which converts the xml in various line
into a single line, but i have trouble using that in the shell script, as the script
reads the parameters variables as commands..

below is the command i found

awk '/<cmk:Service/{ORS="";if(NR!=1)print "\n";}1' /data/file1.xml > /data/file2.txt

below is the script i prepared, its aborting with

Service: not found, no such file or directory
$1 = /<cmk:Service/
$2 = /data
$3 = file1.xml
$4 = file2.txt
$ = file ( prefix for split command)
#!/bin/sh
awk '$1{ORS="";if(NR!=1)print "\n";}1' $2/$3 > $2/$4
split -l 1000 $2/$3 $5

for i in $( ls $5* )
timestamp=`date "+%Y%m%d%H%M%S"`
do
mv -f $5* $5_$timestamp_$i.dat
done

can someone help me on this?

thanks
MJ

$1 is not being expanded as it's within single quotes

try this:

awk "$1"'{ORS="";if(NR!=1)print "\n";}1' $2/$3 > $2/$4

or with $1="<cmk:Service"

awk -v W="$1" '$0 ~ W{ORS="";if(NR!=1)print "\n";}1' $2/$3 > $2/$4

Hi
thanks for your response..

yes, the first step is working with your code..

for second step of splitting the file and renaming, i have modified the code like below

what i'm trying to do is, after i created the single line xml file, i'm splitting that file each
containing 1000 records, by assigning the prefix($5), (this is working fine)

after i splitted the files, i need to rename all the splitted file with $5 and concatinating timestamp and and a individual sequencer number, like below
file2_201401312231_1
this is the part which is not working, can you please help

#!/bin/sh
awk -v W="$1" '$0 ~ W{ORS="";if(NR!=1)print "\n";}1' $2/$3 > $2/$4

split -l 1000 $2/$3 $5

num=1
for i in $( ls $5* )
timestamp=$(date "+%Y%m%d%H%M%S")
do
num=num+1
mv -f $i $5_$timestamp_$num
done

try this:

mv -f "$i" "${5}_${timestamp}_${num}"