in reply to problem count the number of words
Given what wise haukex already said and considering only your title, a simple oneliner can do the task (pay attention to windows double quotes):
perl -lne "$count+=split}{print $count" /path/file1 /path/file2
Using Deparse can give you a working starting point to work with:
perl -MO=Deparse -lne "$count+=split}{print $count" /path/file1 /path +/file2 BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = readline ARGV)) { chomp $_; $count += split(' ', $_, 0); } { print $count; } -e syntax OK
That can be translated in: foreach file in the input ( see ARGV in perlodoc ) read it line by line, chomp each line, split the line at withespaces and add the resulting word count to $count When all file processing is finished print the value of $count
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem count the number of words -- oneliner
by kschwab (Vicar) on Dec 26, 2018 at 16:40 UTC | |
by pme (Monsignor) on Dec 26, 2018 at 17:16 UTC | |
by kschwab (Vicar) on Dec 26, 2018 at 17:38 UTC | |
by pme (Monsignor) on Dec 26, 2018 at 21:00 UTC |