#!/bin/bash
find *.txt | wc -l;
this gives number of txt files. In my program how do I put this output into a variable say "count"
Create a variable to store the file path. Use wc –lines command to count the number of lines. Use wc –word command to count the number of words.
Using wc command. wc command is used to know the number of lines, word count, byte and characters count etc. Count the number of words using wc -w. Here, “-w” indicates that we are counting words.
Words could be counted with sed 's/[[:space:]]/\n/g' filename | grep -c .
The wc command is used to find the number of lines, characters, words, and bytes of a file. To find the number of lines using wc, we add the -l option. This will give us the total number of lines and the name of the file.
#!/bin/bash
count=$(find *.txt | wc -l)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With