bug-bash
[Top][All Lists]
Advanced

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

Re: combine xargs with EOF


From: DJ Mills
Subject: Re: combine xargs with EOF
Date: Wed, 17 Oct 2012 15:18:51 -0400

On Wed, Oct 17, 2012 at 2:56 PM,  <giuseppe.amatulli@gmail.com> wrote:
> so this is my actual gol:
>
> change this loop ( which is working fine )
>
> for file in /weldgfs/p51/gius_urban/pop_urban/tl_2010_us_uac10/UA_tiff/*.tif 
> ; do
>     filename=`basename $file .tif`
>     tile=${filename:3:6}
>     echo processin $file
>     oft-stat $file 
> /weldgfs/p51/gius_urban/LandCover/tree_cover/TREE_COVER_$tile.tif    
> /weldgfs/p51/gius_urban/pop_urban/tl_2010_us_uac10/UA_tree/UA_tree$tile.txt
>     oft-stat $file 
> /weldgfs/p51/gius_urban/LandCover/bare_ground/BARE_GROUND_$tile.tif  
> /weldgfs/p51/gius_urban/pop_urban/tl_2010_us_uac10/UA_bare/UA_bare$tile.txt
> done
>
> in
>
> ls /weldgfs/p51/gius_urban/pop_urban/tl_2010_us_uac10/UA_tiff/*.tif | xargs  
> -n 1 -P 10 bash -c '
> file="$1"
> filename=`basename $file .tif`
> tile=${filename:3:6}
> echo processin $file
> oft-stat $file 
> /weldgfs/p51/gius_urban/LandCover/tree_cover/TREE_COVER_$tile.tif    
> /weldgfs/p51/gius_urban/pop_urban/tl_2010_us_uac10/UA_tree/UA_tree$tile.txt
> oft-stat $file 
> /weldgfs/p51/gius_urban/LandCover/bare_ground/BARE_GROUND_$tile.tif  
> /weldgfs/p51/gius_urban/pop_urban/tl_2010_us_uac10/UA_bare/UA_bare$tile.txt
> ' _
>
>
> for multi process in parallel, without call an external script. . of course 
> the echo $1 was a way to simplify the full task. Now the script works fine
> Thanks to all you
> Ciao
> Giuseppe
>
>

You're still lacking quotes. "$file", never $file. And you have the
same issue with ls.

printf '%s\0' /weldgfs/p51/gius_urban/pop_urban/tl_2010_us_uac10/UA_tiff/*.tif
| xargs -0 -n 1 -P 10 bash -c '
file="$1"
filename=${file##*/} filename=${filename%.tif}
tile=${filename:3:6}
echo "processing $file"
oft-stat "$file"
"/weldgfs/p51/gius_urban/LandCover/tree_cover/TREE_COVER_$tile.tif"
"/weldgfs/p51/gius_urban/pop_urban/tl_2010_us_uac10/UA_tree/UA_tree$tile.txt"
oft-stat "$file"
"/weldgfs/p51/gius_urban/LandCover/bare_ground/BARE_GROUND_$tile.tif"
"/weldgfs/p51/gius_urban/pop_urban/tl_2010_us_uac10/UA_bare/UA_bare$tile.txt"
' _

would be one option...

or do the parallel processing in bash itself... see
http://mywiki.wooledge.org/ProcessManagement
and
https://github.com/e36freak/templates/blob/master/threads or
https://github.com/e36freak/templates/blob/master/parallel



reply via email to

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