I am trying to pass an argument to a script and use that argument in an awk statement. Is there something missing in the code? Its not working! It is creating a file with blank extension.
TIA
-KAT
#!/usr/bin/ksh
if [ $# != 2 ] ;then
echo "usage: $0 argument"
exit
fi
ch_ind="$1" ;export ch_ind
ind_pos="$2" ;export ind_pos
ProcessFiles (){
echo GetFiles
for i in *.svd
do
awk 'BEGIN { count=0;}
{
print_ind=substr($0,'$ind_pos', 1);
if (print_ind=="Y" {
if (count > 0) {
printf("\r\n" > "file."'ch_ind'
}
count=1;
printf("%s", $0) > "file."'$ch_ind'
}
}
' < "$i"
done
}
ProcessFiles
echo done
TIA
-KAT
#!/usr/bin/ksh
if [ $# != 2 ] ;then
echo "usage: $0 argument"
exit
fi
ch_ind="$1" ;export ch_ind
ind_pos="$2" ;export ind_pos
ProcessFiles (){
echo GetFiles
for i in *.svd
do
awk 'BEGIN { count=0;}
{
print_ind=substr($0,'$ind_pos', 1);
if (print_ind=="Y" {
if (count > 0) {
printf("\r\n" > "file."'ch_ind'
}
count=1;
printf("%s", $0) > "file."'$ch_ind'
}
}
' < "$i"
done
}
ProcessFiles
echo done