More UNIX Shell Scripting Help Needed "Bad Number" (KSH)

Saint Nick

Lifer
Jan 21, 2005
17,722
6
81
Here is my code

Code:
#!/usr/bin/ksh

clear

file=/home/x12960/apedi.dat
line_nbr=0    
next_line_nbr=`expr ${line_nbr} + 1`
file_lines=`wc -l ${file}`
outfile=new_apedi.dat

#echo $file
#echo $line_nbr
#echo $next_line_nbr
#echo $file_lines
#echo $outfile

while [[ $line_count -lt $file_lines ]]
do
    line=`sed -n "${line_nbr}p" $file`
    next_line=`sed -n "${next_line_nbr}p" $file`
    
    line_char=`echo $line | cut -c1-1`
    next_line_char=`echo $next_line | cut -c1-1`
    
    if [[ $line_char = "H" ]] ; then    
        if [[ $line_char -eq $next_line_char ]] ; then
            echo $next_line >> $outfile
        fi
    else
        echo $line >> $outfile
    fi

    if [[ $next_line_nbr -eq $file_lines ]] ; then
        line_nbr=`expr $line_nbr + 1`
        next_line_nbr=$next_line_nbr
    else
        line_nbr=`expr $line_nbr + 1`
        next_line_nbr=`echo ${line_nbr}`
    fi
done
But, when I run it, I am getting the following error:

Code:
./apedi.scr[9]: 22 /home/x12960/apedi.dat: bad number
In my file, line 9 is outfile=new_apedi.dat. I'd like to add that when I un-comment my echo statements, the same error shows up, but states it is at line 15 rather than line 9. Also, there are 22 lines in my test file.

Thanks for the help!
 
Last edited:

Saint Nick

Lifer
Jan 21, 2005
17,722
6
81
Turns out that wc also returns the name of the file in the count...how can I get rid of that? There doesn't seem to be a command line option for it... :hmm:

Bleh. Fixed it. Updated the wc line to the following.

Code:
file_lines=`wc -l ${file} | awk '{print $1}'`
 
Last edited: