GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Simple script for analysis one line.
Operating System - HP-UX
1847994
Members
7708
Online
104022
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
back
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
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
05-26-2004 02:03 PM
05-26-2004 02:03 PM
Is there simple script to analysis the character of one line?
For ex: "This is Jeff".........how many "f" in this line..... Result is 2
Thanks.
For ex: "This is Jeff".........how many "f" in this line..... Result is 2
Thanks.
Hero
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2004 03:28 PM
05-26-2004 03:28 PM
Solution
Nothing simple but this is a start:
STRING="This is Jeff"
LEN=${#STRING}
CNTR=1
QTY=0
if [ $LEN -gt 0 ]
then
while [ $CNTR -le $LEN ]
do
CHAR=$(echo $STRING | cut -c $CNTR)
[[ $CHAR = "f" ]] && let QTY=$QTY+1
let CNTR=$CNTR+1
done
fi
echo "There are $QTY 'f' characters"
Bill Hassell, sysadmin
STRING="This is Jeff"
LEN=${#STRING}
CNTR=1
QTY=0
if [ $LEN -gt 0 ]
then
while [ $CNTR -le $LEN ]
do
CHAR=$(echo $STRING | cut -c $CNTR)
[[ $CHAR = "f" ]] && let QTY=$QTY+1
let CNTR=$CNTR+1
done
fi
echo "There are $QTY 'f' characters"
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2004 04:05 PM
05-26-2004 04:05 PM
Re: Simple script for analysis one line.
here is something easy
text="this is jeff"
char="f"
print -- "$text" |
awk -v char="$char" '{
printf("there are %d %s in %s\n",gsub(char,""),char,$0);}'
text="this is jeff"
char="f"
print -- "$text" |
awk -v char="$char" '{
printf("there are %d %s in %s\n",gsub(char,""),char,$0);}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2004 04:21 PM
05-26-2004 04:21 PM
Re: Simple script for analysis one line.
another way would be
text="this is jeff"
char="f"
chars=$(print -- "$text" | tr -dc "$char" )
numChars=${#chars}
print $numChars
text="this is jeff"
char="f"
chars=$(print -- "$text" | tr -dc "$char" )
numChars=${#chars}
print $numChars
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP