1

I am having one script need to add logic that if some one add file from winscp and do not convert into plain text while transfer. so some time we get some special character (^m) in some value, i wanted to remove them Here is my code.

cd $HOME_DIR
if [ $SHELL_STEP = 'step2' ]; then



if [ -s $DATA_DIR/$DATA_FILE.txt ]; then echo "The data file is present." cat -v new_reguest.txt $ awk '{ sub("\r$", ""); print }' new_request.txt > new_request.txt echo "Data file $DATA_FILE.txt found in $DATA_DIR directory." >> $LOG_FILE echo "" >> $LOG_FILE STATUS='good' else echo "The data file has not arrived yet." fi

        if [ $STATUS = 'bad' ]; then
                echo "The data file not found."
                echo "The data file not found." >> $LOG_FILE
                echo "" >> $LOG_FILE
                SHELL_STEP='step5'
        else
                SHELL_STEP='step3'
        fi
fi

I tried to using awk command, but it's not looking good.

please assist.

johnsyweb
  • 136,902
  • 23
  • 188
  • 247
Praveen k. Agrawal
  • 439
  • 1
  • 5
  • 15

1 Answers1

1

Most implementations will provide tools like dos2unix or d2u to remove carriage returns from the end of lines. You can use something like:

dos2unix new_request.txt >new_request_2.txt
mv new_request_2.txt new_request.txt

If you don't have the dos2unix command, you can do the same thing with sed:

sed -i 's/\r$//' new_request.txt

The -i is for in-place editing. If your version of sed doesn't have that, you'll have to resort to the same temporary file trick used in the dos2unix code above.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953