hello
i am running a shell script on hp unix and getting a file with control m characters through teradata fastexport(file name -fast_export_tmp.txt).
to remove the control m i applied cut command :
cat fast_export_tmp.txt|cut -f2 -d'|'>fastexport.txt
i got a perfectely populated file with correct data .
but when i am applying the same process(using cut command over the tmp file) in sun solaris, am getting blank file .
please help me on this
That is a useless use of cat, though that's not the problem.
An alternative command you could try:
awk -F"|" '{ print $2 }' inputfile > outputfile
If that doesn't work, show a sample of the input you have and the output you want.
to remove ^m at the end of lines you can use the command dos2unix
To remove control m, you can simply open the file in vi and do this (I'm assuming you've ^M at the end of each line):
:%s/<ctrl+v+m>$//g
Hi ,
For removing CTRL ^M character you need to user below commands
For Vi editor
%s/^M//g
By sed command
sed 's/^M//g' <filename>
Another way by tr command
tr -d '\r' <filename>
Hope you are looking for the same.
-pankaj
1 Like
awk command is not working either.
input file :
[|104566918;-1;3324231;-1; ; ;; ;; ; ;09-1CQIBM;;T;2009-06-23 02:00:00; ;2012-04-09 14:56:19
[|104566920;-1;3324231;-1;-1; ;; ;; ;;09-1CQIBM;;P;2009-06-23 02:00:00; ;2012-04-09 14:56:19
---------- Post updated at 01:09 PM ---------- Previous update was at 12:58 PM ----------
Thanks pankaj
i have to remove junk character from the file through a shell script .
and this script runs daily and thus we receive 100 of files .
I assume that we can not use the vi edit in shell script.
can you please tell some other way to remove these junk characters ..
---------- Post updated at 01:19 PM ---------- Previous update was at 01:09 PM ----------
I am getting the correct populated file now .
first i have removed the control m characters and then i applied the awk command to get the correct data
sed 's/^M//g' test_export2_tmp.txt|awk -F"|" '{print $2}' > fil2.txt
thanks
To the OP. You can use sed like everyone has said to remove the ^M at the end of each line.
But you can't just type in ^M. To get the ^M, press <CTRL> and "V" at the same time. Then let go and hit <ENTER>.