LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   removing "\r" while using command cp , grep & awk (https://www.linuxquestions.org/questions/linux-newbie-8/removing-%5Cr-while-using-command-cp-grep-and-awk-641159/)

rakesh.tandur 05-09-2008 04:59 PM

removing "\r" while using command cp , grep & awk
 
Hello,
I am using the below command to grep a file & get the 3rd field(which is a file name) of it then copy that to an directory bin.

Command:
cp $(grep "EXETARGET" Makefile | awk '{print 3}') $EB2/build/debug/bin

But getting an error saying " cp: cannot stat 'aljobtemplatemgr\r': no such file or directory"

The name is getting appended by \r.

How do i remove the "\r" from the 'aljobtemplatemgr\r'

Any suggestions is appreciated. Thanks in advance.

Regards
-Rakesh

druuna 05-09-2008 05:17 PM

Hi,

The Makefile you are using as input is probably a dos file, not a unix/linux file, that is why the \r is added.

If creating/changing the Makefile(s) to unix/linux file(s) is not an option:

cp $(awk '/EXETARGET/ {sub(/\r/,"",$3) ; print $3 }' Makefile) $EB2/build/debug/bin

This removes the grep part (not needed, awk can do this also). Awk's sub(x,y,z) function removes the \r from field 3 before printing it.

Hope this helps.

rakesh.tandur 05-09-2008 05:32 PM

Hello,

Its hanging .. never coming out.

druuna 05-09-2008 05:43 PM

Hi,

Having a lot of info to work with is always nice......

I assume that the Makefile is a dos file (is it?).

A sample run:

Code:

$ cat Makefile
asdff
tyuio

EXETARGET secondfield aljobtemplatemgr

erty
asdfa
sdf


$ awk '/EXETARGET/ {sub(/\r/,"",$3) ; print $3 }' Makefile
aljobtemplatemgr

$ cp $(awk '/EXETARGET/ {sub(/\r/,"",$3) ; print $3 }' Makefile) /tmp

 $ ls -l /tmp/al*
-rw-r----- 1 druuna internet 0 May 10 00:38 /tmp/aljobtemplatemgr

Are you using unix or linux?
Are you using gawk (awk --version)? If not, which awk is used?
Is the oneliner an actual oneliner or is it part of a larger (shell) script?

rakesh.tandur 05-09-2008 06:02 PM

Thanks.. It worked.. Missing an space.


All times are GMT -5. The time now is 08:03 AM.