|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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?. |
|
#3
|
|||
|
|||
|
Anyone know of any work around?
|
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Xargs passing value {} twice |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|