View previous topic :: View next topic |
Author |
Message |
manuels Advocate


Joined: 22 Nov 2003 Posts: 2146 Location: Europe
|
Posted: Wed Jul 23, 2008 12:10 pm Post subject: [Bash] mehrere Files als Argumente bei xargs [solved] |
|
|
Hallo zusammen,
ich moechte mir ein Bashscript basteln, das alle *-000.dat, *-001.dat ... *-999.dat Files zusammen einem Programm als Arugmente uebergibt.
Dazu habe ich mir folgendes Script gebastelt:
Code: | #!/bin/bash
set -e
find $1 -iname "*-000.dat" | while read file; do
len=`expr length "$file"`
f=${file:0:$[$len-7]}
f=$(basename "$f")
find $1 -iname "${f}0??.dat" -print0 | xargs -p -n 999 -0 $(dirname $0)/gather
done
|
Das finden und gruppieren der *-???.dat-Dateien klappt alles.
Das einzige woran es jetzt noch hakt ist, dem Programm diese Argumente zu uebergeben (vorletzte Zeile).
xargs will das Programm $(dirname $0)/gather jeweils immer nur fuer eine Datei aufrufen, nicht fuer alle Dateien auf einmal.
Irgendwie raff ich's nicht & ware fuer Tipps dankbar!
Manuel _________________ Build your own live cd with catalyst 2.0!
Last edited by manuels on Wed Jul 23, 2008 1:38 pm; edited 1 time in total |
|
Back to top |
|
 |
69719 l33t

Joined: 20 Sep 2004 Posts: 865
|
Posted: Wed Jul 23, 2008 12:51 pm Post subject: |
|
|
Ich denke du willst so etwas.
Code: |
$(dirname $0)/gather $(find $1 -iname '*-[0-9][0-9][0-9].dat')
|
|
|
Back to top |
|
 |
Necoro Veteran


Joined: 18 Dec 2005 Posts: 1912 Location: Germany
|
Posted: Wed Jul 23, 2008 12:56 pm Post subject: Re: [Bash] mehrere Files als Argumente bei xargs |
|
|
manuels wrote: | xargs will das Programm $(dirname $0)/gather jeweils immer nur fuer eine Datei aufrufen, nicht fuer alle Dateien auf einmal. |
Was ja auch gerade der Sinn von xargs ist  _________________ Inter Deum Et Diabolum Semper Musica Est. |
|
Back to top |
|
 |
69719 l33t

Joined: 20 Sep 2004 Posts: 865
|
Posted: Wed Jul 23, 2008 1:00 pm Post subject: |
|
|
Sein Problem ist das er den stdout von find ließt und jede gelesene Zeile führt ein xargs aus.
Was er in etwa wollte war ein
Code: |
PC411 ~ $ find -iname '*-[0-9][0-9][0-9].dat' | xargs echo
./tmp/muhaha-081.dat ./tmp/muhaha-099.dat
|
Aber mit dem while hat er es kapuut gemacht. Gut zu sehen an.
Code: |
PC411 ~ $ export C=1 && find -iname '*-[0-9][0-9][0-9].dat'|while read L; do echo "LINE "$C" "$L; C=$(expr $C + 1); done
LINE 1 ./tmp/muhaha-081.dat
LINE 2 ./tmp/muhaha-099.dat
|
|
|
Back to top |
|
 |
manuels Advocate


Joined: 22 Nov 2003 Posts: 2146 Location: Europe
|
Posted: Wed Jul 23, 2008 1:38 pm Post subject: |
|
|
Bong! Durch die erste find/while-Schleife war ich so schleifenfixiert, dass ich den Wald vor lauter Baeumen nicht gesehen habe
Danke _________________ Build your own live cd with catalyst 2.0! |
|
Back to top |
|
 |
|