LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-09-2008, 05:59 PM   #1
rakesh.tandur
LQ Newbie
 
Registered: Aug 2007
Posts: 9

Rep: Reputation: 0
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
 
Old 05-09-2008, 06:17 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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.
 
Old 05-09-2008, 06:32 PM   #3
rakesh.tandur
LQ Newbie
 
Registered: Aug 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Hello,

Its hanging .. never coming out.
 
Old 05-09-2008, 06:43 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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?
 
Old 05-09-2008, 07:02 PM   #5
rakesh.tandur
LQ Newbie
 
Registered: Aug 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks.. It worked.. Missing an space.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help :() How to find an address using "grep" & regEx's. linuxmaveric Programming 8 04-28-2010 01:31 AM
How do you do ps ax | grep mozilla | awk '{print "kill " $1}' pppaaarrrkkk Programming 4 03-19-2008 08:17 PM
"grep" Command (SystemV/68 system) xtremexp Other *NIX 3 05-28-2005 08:25 PM
How to use "OR" option in a grep command. sumitarun Programming 3 04-18-2005 02:44 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 04:11 PM


All times are GMT -5. The time now is 04:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration