- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: wc -m results in shell 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
02-03-2004 06:54 AM
02-03-2004 06:54 AM
VAR1=TEST
echo $VAR1 | wc -m
The echo piped to wc returns a value of 5 vs 4. I was looking for 4 as a returned value because "TEST" is only 4 characters.
Thanks for your time.
Ryan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 06:59 AM
02-03-2004 06:59 AM
SolutionFrom man echo:
echo(1) echo(1)
NAME
echo - echo (print) arguments
SYNOPSIS
echo [arg] ...
DESCRIPTION
echo writes its arguments separated by blanks and terminated by a
new-line on the standard output. It also understands C-like escape
conventions; beware of conflicts with the shell's use of \:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 07:02 AM
02-03-2004 07:02 AM
Re: wc -m results in shell script??
John was right on it. It's with echo. Do this
VAR1=TEST
printf "$VAR1" |wc -m
And see it for yourself.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 07:03 AM
02-03-2004 07:03 AM
Re: wc -m results in shell script??
You an adjust your tests if you wish.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 07:08 AM
02-03-2004 07:08 AM
Re: wc -m results in shell script??
Maybe I did something incorrect, but I created a test file and inserted the word "TEST" in the file with vi and saved the file. When I did the "wc -m testfile", I still get 5. The file was called "aaa" and contained the word "TEST". Here is the output from the wc command mentioned above:
5 aaa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 07:10 AM
02-03-2004 07:10 AM
Re: wc -m results in shell script??
Thanks,
Ryan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 07:12 AM
02-03-2004 07:12 AM
Re: wc -m results in shell script??
Same thing. It's the extra "carriage return" character that is causing your problem.
printf "TEST" > file
wc -m file
cat file (you shouldn't get a new line here)
vi file
wc -m file
cat file (you will be put to new line)
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 07:25 AM
02-03-2004 07:25 AM
Re: wc -m results in shell script??
I briefly looked at the man page and it looks like printf does not return escape characters, etc and I am assuming that is why it only shows the result I am expecting. Can you just verify that for me?
Looks like I need to get familiar with printf...
Thanks for your time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 07:29 AM
02-03-2004 07:29 AM
Re: wc -m results in shell script??
printf "TEST" > aaa
wc -m aaa
cat aaa |wc -m
They should now both be 4
Good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 07:30 AM
02-03-2004 07:30 AM
Re: wc -m results in shell script??
That's only to show the example of how extra characters can get in. If you are using printf, you will need to be bit careful as depending on the type of the data you print and it's conversion format, the output may change. It doesn't put a new-line at the end of it's arguments unlike echo.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 07:32 AM
02-03-2004 07:32 AM
Re: wc -m results in shell script??
VAR1=TEST
echo "${VAR1}\c" | wc -m