- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- simple (ish) script, seperate and reparse input st...
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
01-16-2002 04:00 AM
01-16-2002 04:00 AM
Hi,
I'm calling a script as follows:
script 012345678
and I need to take the 012345678
and make it look like this:
in a variable in the script:
"\x00\x21\x43\x65\x87\xFF", 8
where the last 8 is the number of digits input
shold work if the number input is: 0123456789 as:
"\x10\x32\x54\x76\x98\xFF", 9
thanks,
Later,
Bill
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2002 04:25 AM
01-16-2002 04:25 AM
Re: simple (ish) script, seperate and reparse input string
Try:
#!/bin/ksh
echo $1 | awk '{n=$0;l=length($0)
if (l%2 == 1) {n=0.$0}
printf("\"")
for (i=1;i<=l;i=i+2)
{
s1=substr(n,i,1)
s2=substr(n,i+1,1)
printf ("\x%s%s",s2,s1)
}
printf("\xFF\", %d\n",l-1)
}'
The number of digits is 1 less than the *actual* number entered, by the looks of it, i.e. 0123456789 is 10 digits, not 9.
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2002 04:53 AM
01-16-2002 04:53 AM
Re: simple (ish) script, seperate and reparse input string
yea it shouldn't be the l-1, that was my error..
"\x10\x32\x54\x76\x98??", 9
However, I'm getting a strange character appearing just before the closing "
Finally for the 10,
it prints out fine to screen, but how can I set it to a shell variable to work further on it (for a sed)
Thanks,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2002 05:00 AM
01-16-2002 05:00 AM
Re: simple (ish) script, seperate and reparse input string
Shouldn't be the length of 012345678 be 9??
awk '
{
stmp=""
tmp=$1
olenoftmp=length(tmp)
if ( ( olenoftmp % 2 ) != 0 ) {tmp = 0 tmp}
lenoftmp=length(tmp) / 2
for (i = 1; i < lenoftmp+1 ; i++) {
stmp = stmp "\x" substr(tmp,(i*2),1) substr(tmp,(i*2)-1,1)
}
stmp = stmp "\x" "FF," olenoftmp
printf "len of %s is %d\n",stmp,length(stmp)
}'
Don't try changing the "\x" "FF" to "\xFF", other wise awk will make if an FF.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2002 05:01 AM
01-16-2002 05:01 AM
Re: simple (ish) script, seperate and reparse input string
a=`script 012345678`
should do it. I don't get any funny characters when I run it.
Can you pipe the output through | od -c and see what they are.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2002 05:04 AM
01-16-2002 05:04 AM
Re: simple (ish) script, seperate and reparse input string
hithere=`echo $hello |
awk '
{
stmp=""
tmp=$1
olenoftmp=length(tmp)
if ( ( olenoftmp % 2 ) != 0 ) {tmp = 0 tmp}
lenoftmp=length(tmp) / 2
for (i = 1; i < lenoftmp+1 ; i++) {
stmp = stmp "\x" substr(tmp,(i*2),1) substr(tmp,(i*2)-1,1)
}
stmp = stmp "\x" "FF," olenoftmp
printf stmp
}
'`
echo $hithere
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2002 05:22 AM
01-16-2002 05:22 AM
Solutionthe funny character, probably a "y" with a sideways ":" over it is caused by awk interpeting the "\xFF" as a hex FF, that's why I had to seperate the "\x" and the "FF" into two seperate strings.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2002 05:24 AM
01-16-2002 05:24 AM
Re: simple (ish) script, seperate and reparse input string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2002 05:33 AM
01-16-2002 05:33 AM
Re: simple (ish) script, seperate and reparse input string
I was running an old version of awk - the later version was exhibiting your strange chars.
Rgds, Robin.