- 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
Discussions
Discussions
Forums
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
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