Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.73 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # 23. b)
  4. # Write a shell script that for each file from the command line will output the
  5. # number of words that are longer than the number k read from keyboard.
  6. # The output must be ordered by the number of words.
  7.  
  8. echo Enter the number
  9. read k
  10.  
  11. for file in $*  # this iterates through all the files given in the comm line
  12. do
  13.  
  14. # now it will compare the size of each word from the files given and save
  15. # the ones longer than the nr
  16. # wc -l will give the number of those words, and the final output will show
  17. # the number for each file along with the file name, ordered
  18.  
  19.     echo "$(awk -v nr=$k '{ for (i=1; i<=NF; i++)
  20.                                 if (length($i) > nr) print $i
  21.                           }' "$file" |
  22.             wc -l) $file"  | sort -n
  23. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement