riccardinofuffolo

Sistemi Operativi - 07/02/2003 - Es. 4

Aug 15th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.66 KB | None | 0 0
  1. #!/bin/awk -f
  2. # Tema d'esame 07/02/2003 A (www.labinf.polito.it/whitone/index.php?summ=SO)
  3. # Uso: awk -f paragrafi.awk testo.txt
  4. # 15/08/2012 - BNCRCR
  5.  
  6. BEGIN {
  7.     paragrafi = 1       # Se ho solo una riga ho comunque un paragrafo
  8.     precedente_vuota = 0
  9. }
  10.  
  11. # Pattern che identifica una riga vuota
  12. /^$/ {
  13.     if (!precedente_vuota)
  14.         paragrafi++
  15.     precedente_vuota = 1
  16. }
  17.  
  18. # Pattern che identifica una riga con almeno un carattere
  19. /./ {
  20.     precedente_vuota = 0
  21. }
  22.  
  23. END {
  24.     print paragrafi
  25. }
  26.  
  27. # == testo.txt ==
  28. # ciao, sono una linea di testo che delimita un paragrafo
  29. #
  30. #
  31. # io sono un altro paragrafo
  32. # io invece no
  33. #
  34. # quindi alla fine ho tre paragrafi. ciao.
Advertisement
Add Comment
Please, Sign In to add comment