Skip to main content
! instead of ^ for mksh, missing quotes,
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

Yet another implementation that dodoes not reliesrely on external programs, in bash or kshbash, zsh, yash and some implementations/versions of ksh:

while IFS= read -r line; do 
  line="${line//[^\"][!\"]/}"
  echo $"${#line}"
done <input-file

Use line="${line//[^[!(]}"for counting (.

Yet another implementation that do not relies on external programs, in bash or ksh:

while IFS= read -r line; do 
  line="${line//[^\"]/}"
  echo ${#line}
done <input-file

Use line="${line//[^(]}"for counting (.

Yet another implementation that does not rely on external programs, in bash, zsh, yash and some implementations/versions of ksh:

while IFS= read -r line; do 
  line="${line//[!\"]/}"
  echo "${#line}"
done <input-file

Use line="${line//[!(]}"for counting (.

turned off backslash expansion in read (also whitespace mangling, although it would only matter for counting space characters)
Source Link
Gilles 'SO- stop being evil'
  • 866.1k
  • 205
  • 1.8k
  • 2.3k

Yet another implementation that do not relies on external programs, in bash or ksh:

while IFS= read -r line; do 
  line="${line//[^\"]/}"
  echo ${#line}
done <input-file

Use line="${line//[^(]}"for counting (.

Yet another implementation that do not relies on external programs

while read line; do 
  line="${line//[^\"]}"
  echo ${#line}
done <input-file

Use line="${line//[^(]}"for counting (.

Yet another implementation that do not relies on external programs, in bash or ksh:

while IFS= read -r line; do 
  line="${line//[^\"]/}"
  echo ${#line}
done <input-file

Use line="${line//[^(]}"for counting (.

Yet another implementation that do not relies on external programs

while read line; do 
  line="${line//[^\"]}"
  echo ${#line}
done <input-file
while read line; do 
  line="${line//[^\"]}"
  echo ${#line}
done <input-file

Use line="${line//[^(]}"for counting (.

Yet another implementation that do not relies on external programs

while read line; do 
  line="${line//[^\"]}"
  echo ${#line}
done <input-file

Use line="${line//[^(]}"for counting (.

Yet another implementation that do not relies on external programs

while read line; do 
  line="${line//[^\"]}"
  echo ${#line}
done <input-file

Use line="${line//[^(]}"for counting (.

Source Link
enzotib
  • 53.5k
  • 14
  • 126
  • 106
Loading