how to get rid of ^m from sql query
Category: UNIX-Unix Beginner
how to get rid of "^m" from sql query
i've searched the net and tried various solutions that don't work for me.
i'm trying to return values from a sql query and i keep getting a "^m" appended to one field.
code:
getting data from table
select * from table...
spooling to $home/out.log
...
wf_data=`tail -7 $home/out.log | awk '{print $1}'` assigning the values to wf_data variable
echo $wf_data > $home/out.log returning the data to out.log ... (may be dumb way but it works.. i need it for formatting purposes
wf=`tail -1 $home/out.log | awk '{print $1}'` #getting workflow
f=`tail -1 $home/out.log | awk '{print $2}'` #getting folder
s=`tail -1 $home/out.log | awk '{print $3}'` #getting server
u=`tail -1 $home/out.log | awk '{print $4}'` #getting user
p=`tail -1 $home/out.log | awk '{print $5}'` #getting pass
variable wf is having the "^m" appended to it.
any suggestions as to how to remove it?
(i tried sed -i '' "s/\r//g" $home/out.log (along with other variations) right after the sql statements and other sections - didn't work)
try something like:
code:
sed 's/^m//g' logfile
press ctrl key followed by m.
you can get rid of ^m chars by using dos2unix on solaris/linux or dos2ux on hp systems. you can add it (required if you intend to open the file in notepad on windows systems) using unix2dos or ux2dos as above.
quote:
originally posted by ghostdog74
try something like:
code:
sed 's/^m//g' logfile
press ctrl key followed by m.
it should be ctrl-v followd by m
or perhaps just replace the awk '{print $1}' to '{printf $1}'
many thanks to everyone.
i used matrixmadhan and ghostdog74 suggestions and it worked like a charm.
great success
