- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: what is the meaning of the 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-23-2008 01:32 AM
06-23-2008 01:32 AM
what is the meaning of the script?
customer has a script as following description.
#>aa=`tr '\0a' '?'
#echo $aa
4167798
Best regards,Louis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2008 01:42 AM
06-23-2008 01:42 AM
Re: what is the meaning of the script?
It seems like there are problems. You only have octal escape sequences for tr(1). If it truly wants to translate a newline, it should use "\012".
So the script translates something into "?" in file salv_xxxt001.dmp, then uses grep to count the number of "?". That is assigned to aa and then it is echoed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2008 06:00 AM
06-23-2008 06:00 AM
Re: what is the meaning of the script?
I don't understand the convolutions here.
If the goal is simply to count newline (0x0a) characters, simply use 'wc -l file'.
The command you show shouldn't work to count lines since 'grep' is going to process *lines* and the left side of the pipe destroys the lines. That is, you are going to count the number of lines (one big long one!) with multiple "?" characters in it, thus returning a count of one.
If the object is to count some number of characters, this is fast:
# perl -nle '$n+=tr/x/x/;END{print $n}'
...substitute for 'x' the charcter you want counted.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2008 08:49 PM
06-23-2008 08:49 PM
Re: what is the meaning of the script?
I took a look at this and it seems that it is doing is translating null chars to "?". The "a" is ignored since there is only one "?".
So it is counting the sum of null + "?" chars.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2008 04:22 AM
06-24-2008 04:22 AM
Re: what is the meaning of the script?
> Dennis: I took a look at this and it seems that it is doing is translating null chars to "?". The "a" is ignored since there is only one "?".
Yes! I agree with you now! Consider:
# make a file with nulls and "a"s:
# perl -e 'print "\0a\n" for 1..10' > funnyfile
# cat -e funnyfile
^@a$
^@a$
^@a$
^@a$
^@a$
^@a$
^@a$
^@a$
^@a$
^@a$
# perl -nle '$n+=tr{\0}{\0};END{print $n}' funnyfile
10
# tr '\0a' '?' < funnyfile|grep -c '?'
10
...BUT this is much cleaner:
# tr '\0' '?' < funnyfile|grep -c '?'
10
...Observe that the shell 'tr' drops the "a" as Dennis noted, whereas Perl will not. Perl's 'tr' transliterates ALL occurrences of the characters found in the search list with the corresponding character in the replacement list!
# perl -nle '$n+=tr{\0a}{\0a};END{print $n}' funnyfile
20
Regards!
...JRF...