To find number of char occur


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To find number of char occur
# 15  
Old 03-31-2010
its working for me.
Code:
/home-dev/->echo 'a|b|c|d|z' | tr -dc 'a' | wc -c
1
/home-dev/->echo 'a|b|c|d|z' | tr -dc 'd' | wc -c
1
/home-dev/->

which OS do you have?
# 16  
Old 03-31-2010
i'm doing in cygwin
# 17  
Old 03-31-2010
Yet another Perl version:

Code:
% echo "a|b|c|d|z"|perl '-nEsay~~@{[/\|/g]}' 
4



---------- Post updated at 08:37 AM ---------- Previous update was at 08:34 AM ----------

Quote:
Originally Posted by posix
i'm doing in cygwin
I cannot reproduce this:
Code:
% uname 
CYGWIN_NT-5.1
% echo 'a|b|c|d|z' | tr -dc a | wc -c
1
% echo 'a|b|c|d|z' | tr -dc d | wc -c
1

# 18  
Old 03-31-2010
@Radoulov
Code:
% uname 
CYGWIN_NT-5.1
% echo 'a|b|c|d|z' | tr -dc a | wc -c
1
% echo 'a|b|c|d|z' | tr -dc d | wc -c
1

Yes , you are correct i got the exact result .what you are getting.Actually i placed print in place of echo so that i got the erroneous result, As print command is not found in CYGWIN_NT-5.1.

Thank & Regard's
posix
# 19  
Old 03-31-2010
Quote:
Originally Posted by posix
As print command is not found in CYGWIN_NT-5.1.
[...]
Just to clarify that print is not OS specific, but shell specific:
some shells (ksh (and ksh clones), zsh) provide the print builtin command:

Code:
$ for sh in bash zsh ksh; do
  eval "$sh -c 'echo \$0 \$(type print)'"
done> >
bash: type: print: not found
bash
zsh print is a shell builtin
ksh print is a shell builtin

# 20  
Old 03-31-2010
Code:
echo 'a|b|c|d|z' | sed 's/[^[:punct:][:punct:]]*/\n/g'|sed '/./!d' | wc -l

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

2. UNIX for Dummies Questions & Answers

Remove char if not a number

I need to write a BASH script that takes a 2 character string and removes the second character if it is not a digit e.g. If the string is numberical value >9 e.g. string1 = '34' then leave string1 = '34'. However if the string is <10 e.g. string1 = '3X' then remove the second char (which... (7 Replies)
Discussion started by: millsy5
7 Replies

3. Shell Programming and Scripting

To find char field and replace null

hi, i having a file with | seperated in which i need to search char in 3rd column and replace with null. i need to replace only the coulmn where character occurs in 3rd field for eg: file1.txt xx|yy|xx|12 output file: xx|yy||12 (5 Replies)
Discussion started by: rohit_shinez
5 Replies

4. Shell Programming and Scripting

How count number of char?

hello how can i cont number of char with loop coomand? i dont want to use wc or other special command the script should check all word's char. one by one also a counter can handle the number As noted in other threads started today. This is not the correct forum for homework assignments. ... (2 Replies)
Discussion started by: nimafire
2 Replies

5. Shell Programming and Scripting

awk to find lines containing word that occur multiple times

i have a script that scans a log file every 10 minutes. this script remembers the last line of the log and then uses it to continue monitoring the log when it runs again 10 minutes later. the script searches the log for a string called MaxClients. now, how can i make it so that when the... (7 Replies)
Discussion started by: SkySmart
7 Replies

6. Shell Programming and Scripting

find only 6 char long

find /tmp -type f -mtime +180 I have this script get the list to clean up files older than 180 days under /tmp. But, I want to make sure to grep only a type of files, which have only 6 character long. .... LT3hqa dRMoya ... (16 Replies)
Discussion started by: Daniel Gate
16 Replies

7. Shell Programming and Scripting

Find and replace all extended char.

Hi Guys, I wand find and replace all Extended ASCII Codes from all my log files. My Log files: /home/Kalr/PPool/Output i have logs file in sub dir. /home/Kalr/PPool/Output/X /home/Kalr/PPool/Output/Y /home/Kalr/PPool/Output/Z My Abc.log file input: Extended ASCII Codes :– ... (4 Replies)
Discussion started by: asavaliya
4 Replies

8. Shell Programming and Scripting

how to get number char from a string

for example: i hav a string like : /rmsprd/arch01/rmsprd/rmsprdarch72736.log how I can extract my_num=72736? I know I can echo "/rmsprd/arch01/rmsprd/rmsprdarch72736.log" | tr "/" " " | awk '{ print $4 }' to get rmsprdarch72736.log (4 Replies)
Discussion started by: netbanker
4 Replies

9. Shell Programming and Scripting

Number of specific char in a string.

I wish to compute the number of dot chars in a string. Example: VAR="aaaa.bbbbb.cccc" I try the shortest command to solve this test. Thanks in advance for your help. Regards, Giovanni (7 Replies)
Discussion started by: gio123bg
7 Replies
Login or Register to Ask a Question