I have a comma delimited file that has a set of data every four lines. I run the following script to get the four lines all on one line. I then import the file into a database. The script works fine when I run it under Windows with cgywin. When I run it in Bash on Mandrake, the script appears to be fine but it has an extra space where each line is joined.
For example, line 1 is A,B,C and line 2 is D,E,F. The script on Windows makes it Line 1 A,B,C,D,E,F,etc. On Mandrake, the script makes it A,B,C ,D,E,F ,. The problem is that the database program reads these spaces as line breaks (so I guess that means they may not be spaces after all but something else).
I want to be able to run this script on Mandrake because my Mandrake is on a much faster computer. Any hints as to why its doing this? Otherwise the script appears to run fine.
Also, I've been trying to fool around with awk to fix the file after running the first script on Mandrake, but since I am so new with it, I've been having some difficulty. Any help there will be appreciated.
The script is below:
#!/bin/sh
COUNT=0
CURRENT_STR=""
NEXT=""
while [ 1 ]; do
COUNT=0
while [ $COUNT -lt 4 ]; do
read NEXT
if [ "x$NEXT" = "x" ]; then
exit;
fi
if [ "x$CURRENT_STR" = "x" ]; then
CURRENT_STR=$NEXT
else
CURRENT_STR="$CURRENT_STR,$NEXT"
fi
COUNT=`expr $COUNT + 1`
done
echo $CURRENT_STR
CURRENT_STR=""
done
For example, line 1 is A,B,C and line 2 is D,E,F. The script on Windows makes it Line 1 A,B,C,D,E,F,etc. On Mandrake, the script makes it A,B,C ,D,E,F ,. The problem is that the database program reads these spaces as line breaks (so I guess that means they may not be spaces after all but something else).
I want to be able to run this script on Mandrake because my Mandrake is on a much faster computer. Any hints as to why its doing this? Otherwise the script appears to run fine.
Also, I've been trying to fool around with awk to fix the file after running the first script on Mandrake, but since I am so new with it, I've been having some difficulty. Any help there will be appreciated.
The script is below:
#!/bin/sh
COUNT=0
CURRENT_STR=""
NEXT=""
while [ 1 ]; do
COUNT=0
while [ $COUNT -lt 4 ]; do
read NEXT
if [ "x$NEXT" = "x" ]; then
exit;
fi
if [ "x$CURRENT_STR" = "x" ]; then
CURRENT_STR=$NEXT
else
CURRENT_STR="$CURRENT_STR,$NEXT"
fi
COUNT=`expr $COUNT + 1`
done
echo $CURRENT_STR
CURRENT_STR=""
done