Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo Leute,

ich bin neu hier, hoffentlich bin ich im richtigen tread. Ich habe in der Uni eine Aufgabe zum Shellskripting bekommen.

Schreiben Sie eine Shellprozedur, die die Anzahl der worte von allen Dateien in einem Verzeichnis in entsprechender Weise ausgibt z.B. in der Form: "die Anzahl der Worte un Datei dateiname ist ###"

So ich habe diese Aufgabe mit einer for-Schleife gelöst. Mit while-Schleife komme ich leider nicht weit.

Hier mal die Lösung mit der for-Schleife:

#! /bin/bash

#Aufgabe 1 - Uebungsblatt 6

#set x

gesamtzahl=0

for datei in *.txt

do

anzahl=`less $datei | wc -w`

echo -e "Die Anzahl der Worte in Datei $datei ist $anzahl"

gesamtzahl=`expr $anzahl + $gesamtzahl`

echo -e "bis jetzt wurden $gesamtzahl Wörter gezählt"

done

Danke für eure Bemühungen.

Gruß, Vitaly.

Und wie sieht dein Ansatz mit einer while-Schleife aus?


$ ls *.txt | while read file

do

   echo $file

done

Bearbeitet von lupo49

Hallo, danke für schnelle antwort.

Also mein Ansatz war anders:

files=`dir *.txt | wc -w` # anzahl der dateien ermitteln

helpVar=`find *.txt`

while [ $files -gt 0 ]

do

-----------------

files=$(($files-1))

done

aber ich kam einfach nicht auf das innere der while schleife. Ich bedanke mich noch mal.

Frohe Weihnachten.

MfG, Vitaly.

for str in $(printf "%s_%s\n" $(wc -w *.txt));do if [[ ${str#*_} == insgesamt ]];then printf "die Anzahl der Wörter insgesamt ist %s\n" ${str%%_*};else  printf "die Anzahl der Wörter in Datei %s ist\t%i\n" ${str#*_} ${str%%_*};fi;done

vieleicht noch nen bisschen die Formatierung aufhuebschen.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.