UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 2nd, 2008, 02:27 PM
krisrmgua krisrmgua is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 64 krisrmgua User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 36 m 37 sec
Reputation Power: 4
Xargs passing value {} twice

I'm doing a list of files in a directory and greping out a certain file name global_log and then trying to grep in all those files for a NAME and then out put those lines into a txt file of the same name as the source file.

Here is what i have:
Code:
ls -la | grep global_log | awk '{print $8}' | xargs -i grep NAME {} > {}.txt


All this works:
Code:
ls -la | grep global_log | awk '{print $8}' | xargs -i grep NAME {}


The problem is when i add on the last part
Code:
 > {}.txt


Instead of creating a file for each file it just creates one file called {}.txt instead of the name it holds.

Any idea where im going wrong?

Reply With Quote
  #2  
Old May 5th, 2008, 01:10 PM
Ehlanna's Avatar
Ehlanna Ehlanna is offline
Not a clue what to put ...
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: in front of this keyboard
Posts: 814 Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 5 h 8 m 11 sec
Reputation Power: 243
It may be due to the > {}.txt being seen as outside the scope of the xargs command.
__________________
According to Sod's Law, buttered toast lands butter side down, when dropped.
Per nature, cats always land on their feet.
So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
.

Reply With Quote
  #3  
Old May 5th, 2008, 01:51 PM
krisrmgua krisrmgua is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 64 krisrmgua User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 36 m 37 sec
Reputation Power: 4
Anyone know of any work around?

Reply With Quote
  #4  
Old May 6th, 2008, 04:01 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Novice (500 - 999 posts) Click here for more information
 
Join Date: Mar 2006
Posts: 671 SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 23 h 26 m 49 sec
Reputation Power: 196
You could try and 'cheat' - this is off top of head so no guarantee ...

Code:
ls -la | grep global_log | awk '{print $8}' | xargs -i tname={} | grep NAME $tname > $tname.txt 
__________________
"I feel so miserable without you; it's almost like having you here" - Stephen Bishop

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Xargs passing value {} twice


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway