- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk with two variables in sh script
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
06-04-2003 01:44 AM
06-04-2003 01:44 AM
awk with two variables in sh script
As $1 i get a string with variable stringlength.
With awk '{print length($1)}' i want to get the stringlength of $1 in an variable like bl.
This variable has to be used in the script.
How the variable can be used from stdin?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2003 01:58 AM
06-04-2003 01:58 AM
Re: awk with two variables in sh script
echo $1
bl=$(echo $1 | awk "{print length(\"$1\")}")
echo $bl
good luck,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2003 02:10 AM
06-04-2003 02:10 AM
Re: awk with two variables in sh script
I wouldn't use awk in this case :
#!/usr/bin/sh
L=${#1}
echo "length of '$1' is $L"
would be easier ...
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2003 02:58 AM
06-04-2003 02:58 AM
Re: awk with two variables in sh script
typeset -i length=$(echo $1|wc -c)-1
echo $length
length is then the integer value of the string length of $1
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2003 03:13 AM
06-04-2003 03:13 AM
Re: awk with two variables in sh script
and if you NEED to use awk:
string=$1
bl=$(echo $string | awk '{print $1}' | wc -m)
echo $bl
of course this can be done without awk completely
bl=$(echo $1 | wc -m)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2003 10:00 AM
06-06-2003 10:00 AM
Re: awk with two variables in sh script
let c=$(echo $1 | wc -m)-1
= Mike =
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2003 02:14 PM
06-06-2003 02:14 PM
Re: awk with two variables in sh script
If you want to work with a list of strings on stdin, then follow this model:
#!/usr/bin/sh
while read string
do
length=${#string}
echo $length $string
done