[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] BASH: sammenligne to tekstfiler



Lars Boye Hansen wrote:

1) sammenligne de to filer og tjekke om filnavn i RemoteDir.txt findes i Unzippet.txt; 2) hvis ja gøres ingenting; 3) hvis nej hentes filen, den unzippes og filnavnet tilføjes til Unzippet.txt.

Under forudsætning af at Remotedir.txt og Unzippet.txt har een fil per linje, så vil følgende måske kunne bruges:

grep "" Unzippet.txt Remotedir.txt | sort -k2 | uniq -c -f1 | grep -E "1.Remotedir.txt" | while read line; do
remotefile=${line#*:}
echo "Hent $remotefile fra ftp-server"
echo "Unzip $remotefile"
echo "Tilføj $remotefile til Unzippet.txt (echo $remotefile >> Unzippet.txt)"
done


Forklaring:

"grep "" Unzippet.txt Remotedir.txt" tilføjer filnavnet til alle linjer.
"sort -k2" sorterer på felt 2 (filnavnet)
"uniq -c -f1" ser efter unikke linjer, men springer felt 1 over.
"grep -E "1.Remotedir.txt" finder nu de linjer hvoer der er nøjagtig 1 filnavn og som kommer fra Remotedir.txt.


Derefter er vi tilbage til almindelig shell-scripting igen

Med venlig hilsen
Bjørn Bille Højte





 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *