- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: how to count special characters?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 04:16 AM
08-08-2005 04:16 AM
for example, I have a string
1,2,3,4,6
how do I find the number of "," in the string?
thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 04:19 AM
08-08-2005 04:19 AM
Re: how to count special characters?
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 04:22 AM
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 04:22 AM
08-08-2005 04:22 AM
Re: how to count special characters?
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 04:23 AM
08-08-2005 04:23 AM
Re: how to count special characters?
awk '{FS=",";}{print $NF-2}' < inputfile
If there are no commas, it will issue a "-1 or -2" for that line.
For the line above, it will yield 4
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 04:24 AM
08-08-2005 04:24 AM
Re: how to count special characters?
try
A="a,b,c,d,e,"
echo $A | awk -v var1="," '{print gsub(var1," ");}'
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 04:31 AM
08-08-2005 04:31 AM
Re: how to count special characters?
"echo 1,2,3,46 | tr -cd '\,' | wc -c"
is a very interesting use of "tr".
May I ask more questions?
can you explain more on "tr -cd"
-c is "first complement SET1", what does it mean?...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 05:04 AM
08-08-2005 05:04 AM
Re: how to count special characters?
For example the following command makes the non-alphabetic characters in a file stand out by translating them to a number sign.
# tr -c '[A-Z][a-z]' '[#*]' < input_file
hope it helps!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 09:22 AM
08-08-2005 09:22 AM
Re: how to count special characters?
==============================================================
#include
#define SPLCHR ','
main()
{
int nc, c;
while ((c = getchar()) != EOF)
if (c == SPLCHR)
++nc;
printf("Number of commas in the input string is: %d\n", nc);
}
==============================================================
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 08:35 PM
08-08-2005 08:35 PM
Re: how to count special characters?
echo 1,2,3,4|awk -F, '{print NF-1}'
This counts the number of fields separted by ',' minus 1 giving you the number of the separtor.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 08:43 PM
08-08-2005 08:43 PM
Re: how to count special characters?
a5:/u/usr/merijn 102 > freq .tcshrc
|nul 0| 1175|@ 6|` 34|
|soh 0|! 3|A 57|a 116|
|stx 0|" 104|B 8|b 75|
|etx 0|# 32|C 39|c 118|
|eot 0|$ 113|D 35|d 102|
|enq 0|% 42|E 99|e 415|
|ack 0|& 28|F 13|f 99|
|bel 2|' 66|G 8|g 25|
|bs 0|( 58|H 54|h 82|
|ht 192|) 60|I 37|i 207|
|lf 253|* 5|J 0|j 4|
|vt 0|+ 11|K 2|k 20|
|ff 0|, 27|L 45|l 138|
|cr 0|- 57|M 70|m 66|
|so 0|. 38|N 47|n 193|
|si 0|/ 199|O 80|o 137|
|dle 0|0 61|P 72|p 128|
|dc1 0|1 33|Q 3|q 3|
|dc2 0|2 21|R 76|r 171|
|dc3 0|3 19|S 77|s 312|
|dc4 0|4 6|T 93|t 278|
|nak 0|5 7|U 28|u 61|
|syn 0|6 12|V 8|v 79|
|etb 0|7 1|W 0|w 26|
|can 0|8 11|X 6|x 17|
|em 0|9 3|Y 14|y 37|
|sub 0|: 72|Z 1|z 1|
|esc 9|; 17|[ 9|{ 17|
|fs 0|< 4|\ 6|| 19|
|gs 0|= 163|] 8|} 17|
|rs 0|> 1|^ 14|~ 10|
|us 0|? 38|_ 25|del 0|
a5:/u/usr/merijn 103 >
freq also supports -a to show the 8-bit characters
Since many systems don't have it, I have included/attached the source code
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 08:57 PM
08-08-2005 08:57 PM
Re: how to count special characters?
echo 1,2,3,4,6 | perl -ne 's/[^,]//g;print length,"\n";'
hth.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2005 12:15 AM
08-09-2005 12:15 AM
Re: how to count special characters?
please, could you assign points?
0 point for this, of course
THX,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2005 11:18 AM
08-22-2005 11:18 AM
Re: how to count special characters?
my apology. let me assign some points now.