The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To call/execute a shell script from a shell script konark UNIX for Dummies Questions & Answers 1 10-26-2007 02:16 PM
How to Run a shell script from Perl script in Parent shell? hifake Shell Programming and Scripting 16 08-28-2007 05:42 PM
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 1 04-30-2007 05:43 AM
rediretion and pipes in DOS shell cmd interpreter jerardfjay Windows & DOS: Issues & Discussions 2 11-03-2006 03:42 PM
PIPEs and Named PIPEs (FIFO) Buffer size Jus Filesystems, Disks and Memory 1 08-20-2004 07:14 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-21-2006
Registered User
 

Join Date: Oct 2006
Posts: 1
Question Shell-Script und Pipes

Hi, beginne gerade mich in der UNIX Welt zu recht zu finden : habe nun folgendes Anliegen, hoffe ihr könnt mir helfen (ist sicher trival für euch, sorry dafür -) )

Ich möchte mir ein kleines Shell-Script schreiben , welches mir dateien eines bestimmten verzeichnisses anhand der Anzahl der enthaltenen Wörter vergeleicht und anschließend die Dateien sortiert ausgibt.

Ich weiß der befehl wc -w zählt die Wörter einer Datei und der Befehl sort sortiert

Problem : Ich muss ja nun erstmal die dateien anhand der Anzahl der Wörter vergelichen, sprich die Wörter zählen : wc -w datei1 datei1 : zählt die Wörter in datei1 und ind datei2 und gibt ergebnis aus ; soweit so gut : ich wollte nun für mein verzeichnis folgendes probieren : find <verzeichnis> -name *.txt | wc -w ; bekomme als Ergebnis aber leider nur die Anzahl der dateien raus und nicht die Anzahl der Wörter in dieser : es werden 3 Dateien gefunden und gelistet und diese drei Dateien wollte ich nun an die Standardeingabe von wc reichen, damit wc entsprechend arbeitet ( wie wc -w dateie1 datei2) das tut die shell offensichtlich nicht : wc zählt die Anzahl der dateien ????????

Wiegesagt bin neu , bin für jeden Tipp dankbar,

lieben Gruß

Anja
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-21-2006
Registered User
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
Quote:
Originally Posted by anja_22
Hi, beginne gerade mich in der UNIX Welt zu recht zu finden : habe nun folgendes Anliegen, hoffe ihr könnt mir helfen (ist sicher trival für euch, sorry dafür -) )

Ich möchte mir ein kleines Shell-Script schreiben , welches mir dateien eines bestimmten verzeichnisses anhand der Anzahl der enthaltenen Wörter vergeleicht und anschließend die Dateien sortiert ausgibt.

Ich weiß der befehl wc -w zählt die Wörter einer Datei und der Befehl sort sortiert

Problem : Ich muss ja nun erstmal die dateien anhand der Anzahl der Wörter vergelichen, sprich die Wörter zählen : wc -w datei1 datei1 : zählt die Wörter in datei1 und ind datei2 und gibt ergebnis aus ; soweit so gut : ich wollte nun für mein verzeichnis folgendes probieren : find <verzeichnis> -name *.txt | wc -w ; bekomme als Ergebnis aber leider nur die Anzahl der dateien raus und nicht die Anzahl der Wörter in dieser : es werden 3 Dateien gefunden und gelistet und diese drei Dateien wollte ich nun an die Standardeingabe von wc reichen, damit wc entsprechend arbeitet ( wie wc -w dateie1 datei2) das tut die shell offensichtlich nicht : wc zählt die Anzahl der dateien ????????

Wiegesagt bin neu , bin für jeden Tipp dankbar,

lieben Gruß

Anja

Hi Anja

Ich versuchte, zu übersetzen, was u mit google schrieb, aber noch, das es bilden doesnt Menge von der Richtung… du sie auf englisch versuchen und bekanntgeben kann? Die übersetzung ist unten zugunsten jedermann, das englisch spricht und es heraus darstellen kann.

(For english speakers,the above is the translation of what is below in english, for anja's sake)
I tried translating what u wrote with google, but still it doesnt make a lot of sense... can you try and post it in english? The translation is below for the benefit of anyone who knows english and can figure it out.

Rear one, begins to find straight me in the UNIX world rightfully: now if the following request has, hope you can me help (is safe trival for you, sorry for it -)) I would like to be written a small shell Script, which me files of a certain listing on the basis the number of contained words gel-calibrated and afterwards sorted spends the files. I know the instruction wc - w counts the words of a file and the instruction sort sorted Problem: I must now first times the files on the basis the number of words vergelichen, speak the words to count: wc - w datei1 datei1: and ind datei2 counts the words in datei1 and spends result; so far so well: I wanted to try now for my listing the following: find <verzeichnis> - name *.txt | wc - w; get as result however unfortunately only the number of files raus and not the number of words in this: 3 files are found and listed and these three files wanted to be enough I now to the standard input of wc, so that wc works accordingly (like wc - w dateie1 datei2) does the shell obviously not: wc the number of files counts???????? Cradle-said are new, are for everyone tap gratefully, love greeting Anja


Arggggggggghhhhhhhhh!!!!!!!!!
Reply With Quote
  #3 (permalink)  
Old 10-21-2006
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 513
Quote:
Originally Posted by napoloyan
(For english speakers,the above is the translation of what is below in english, for anja's sake)
I tried translating what u wrote with google, but still it doesnt make a lot of sense... can you try and post it in english? The translation is below for the benefit of anyone who knows english and can figure it out.
Don't try too hard for a thing which is against the rules of these forums. All posters are supposed to post in English, if OP doesn't know English, he should look for some other available internet resources, we don't entertain non-English queries here and you are requested to not to encourage non-English posters.

Regards,
Tayyab
Reply With Quote
  #4 (permalink)  
Old 10-24-2006
Registered User
 

Join Date: Oct 2006
Posts: 18
Since I'm feeling nice, here's a translation:

Quote:
Hi, beginne gerade mich in der UNIX Welt zu recht zu finden : habe nun folgendes Anliegen, hoffe ihr könnt mir helfen (ist sicher trival für euch, sorry dafür -) )
Hi, I'm just starting to find my way around the UNIX world and now have the following problem, I hope you guys can help (its most probably trivial for you and I'm sorry for that)

Quote:
Ich möchte mir ein kleines Shell-Script schreiben , welches mir dateien eines bestimmten verzeichnisses anhand der Anzahl der enthaltenen Wörter vergeleicht und anschließend die Dateien sortiert ausgibt.
I want to write a small Shell-Script which compares my files in a particular folder and then sorts it out according to the number of words contained.

Quote:
Ich weiß der befehl wc -w zählt die Wörter einer Datei und der Befehl sort sortiert
I know the command 'wc -w' counts the number of words in a file and the command 'sort', sorts the files

Quote:
Problem : Ich muss ja nun erstmal die dateien anhand der Anzahl der Wörter vergelichen, sprich die Wörter zählen : wc -w datei1 datei1 : zählt die Wörter in datei1 und ind datei2 und gibt ergebnis aus ; soweit so gut : ich wollte nun für mein verzeichnis folgendes probieren : find <verzeichnis> -name *.txt | wc -w ; bekomme als Ergebnis aber leider nur die Anzahl der dateien raus und nicht die Anzahl der Wörter in dieser : es werden 3 Dateien gefunden und gelistet und diese drei Dateien wollte ich nun an die Standardeingabe von wc reichen, damit wc entsprechend arbeitet ( wie wc -w dateie1 datei2) das tut die shell offensichtlich nicht : wc zählt die Anzahl der dateien ????????
My Problem: I have to first compare the files for number of words: e.g. 'wc -w file1 file2' compares the number of words in file1 and file2 and gives me the result. so far so good. Then i want to try the following for my folder: 'find <folder> -name *.txt| wc -w'

This unfortunately gives me the number of files, not the number of words in these files. So, if 3 files are found and listed, I want to now pass these 3 as input to wc so that wc can do its magic on them (e.g. wc -w file1 file2). For some reason the shell doesn't do this and wc counts the number of files????

Quote:
Wiegesagt bin neu , bin für jeden Tipp dankbar
Like I said, I'm new and am thankful for every tip

Phew
Reply With Quote
  #5 (permalink)  
Old 10-24-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Code:
for file in $(find <directory> -name '*.txt'); do
  wc -w $file
done
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0