bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xargs combined with awk


From: Steven W. Orr
Subject: Re: xargs combined with awk
Date: Thu, 20 Dec 2012 10:51:16 -0500
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0

On 12/20/2012 10:43 AM, giuseppe.amatulli@gmail.com wrote:
Hi,
have this a for loop which is sending the "dir" variable one for each processor.


for dir in UA_tile_tif_pop_txt UA_buf10_tile_tif_pop_txt 
UA_buf20_tile_tif_pop_txt UA_buf30_tile_tif_pop_txt UA_buf40_tile_tif_pop_txt 
UA_buf50_tile_tif_pop_txt ; do echo $dir ; done | xargs  -n 1 -P 6 bash -c '
IN_UA=/weldgfs/p51/gius_urban/pop_urban/buffer_tif
dir="$1"

join -1 2  -2 1 $IN_UA/$dir/UA_block_sum_s.txt     $IN_UA/$dir/UA_popD_all.txt     
  > $IN_UA/$dir/UA_block_sum_popD.txt
join -1 2  -2 1 $IN_UA/$dir/UA_block_sum_popD.txt  $IN_UA/$dir/UA_hunitD_all.txt 
> $IN_UA/$dir/UA_block_sum_popD_hunitD.txt

' _

The loop works fine, no issues.
When i'm insert an awk command in the -c ' ' _
I get an error.

e.g.


for dir in UA_tile_tif_pop_txt UA_buf10_tile_tif_pop_txt 
UA_buf20_tile_tif_pop_txt UA_buf30_tile_tif_pop_txt UA_buf40_tile_tif_pop_txt 
UA_buf50_tile_tif_pop_txt ; do echo $dir ; done | xargs  -n 1 -P 6 bash -c '
IN_UA=/weldgfs/p51/gius_urban/pop_urban/buffer_tif
dir="$1"

awk '{ print $2 }' $IN_UA/$dir/UA_block_sum_s.txt  > $IN_UA/$dir/test.txt

' _


awk: cmd. line:1: {
awk: cmd. line:1:  ^ unexpected newline or end of string


I try to escape with the \ the ' and the } but no good results.
any idea how how i can insert awk function in xargs bash -c '  '_ syntax?

I would like to avoid to create an external script and called it by
xargs bash myscript.sh

# Change this
awk '{ print $2 }' $IN_UA/$dir/UA_block_sum_s.txt  > $IN_UA/$dir/test.txt

# to this
awk \"{ print \$2 }\" $IN_UA/$dir/UA_block_sum_s.txt  > $IN_UA/$dir/test.txt

You were already in a single quoted string, so your awk code terminated it.

Steve Orr





reply via email to

[Prev in Thread] Current Thread [Next in Thread]