- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script help: awk input string parsing
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-21-2002 02:23 AM
01-21-2002 02:23 AM
got this script from here:
RTN=`echo $1 | awk '
{
stmp="\""
stmp=sprintf("%s%s%sx%s",stmp,"\\\\","\\\\","81")
tmp=$1
olenoftmp=length(tmp)
if ( ( olenoftmp % 2 ) != 0 ) {tmp = 0 tmp}
lenoftmp=length(tmp) / 2
for (i = 1; i < lenoftmp+1 ; i++) {
stmp = sprintf("%s%s%sx%s%s",stmp,"\\\\","\\\\",substr(tmp,(i*2),1),substr(tmp,
(i*2)-1,1))
}
stmp = sprintf("%s%s%sxF7\",%d",stmp,"\\\\","\\\\",olenoftmp+1)
printf stmp
}
'`
echo RTN
That produces this o/p:
./file 1234567
"\x81\x10\x32\x54\x76\xF7",8
but I need it in fact to do this:
"\x81\x10\x32\x54\x76\xF7",6
where the last 6 is the number of \x 's
and
the 81 is because there is an odd number of input digits.
If the number of digits is even
"\x10\x21\x43\x65\x87\xFF",6
any help appreciated..
Thanks,
Bill
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2002 04:33 AM
01-21-2002 04:33 AM
Re: script help: awk input string parsing
RTN=`echo $1 | awk '
{
stmp="\""
stmp=sprintf("%s%s%sx%s",stmp,"\\\\","\\\\","81")
tmp=$1
olenoftmp=length(tmp)
if ( ( olenoftmp % 2 ) != 0 ) {tmp = 0 tmp}
lenoftmp=length(tmp) / 2
for (i = 1; i < lenoftmp+1 ; i++) {
stmp = sprintf("%s%s%sx%s%s",stmp,"\\\\","\\\\",substr(tmp,(i*2),1),substr(tmp,
(i*2)-1,1))
numb=sprintf("%s",i)
}
stmp = sprintf("%s%s%sxF7\",%d",stmp,"\\\\","\\\\",i+1)
printf stmp
}
'`
will produce (12345)
"\x81\x21\x43\x65\xF7",5
and (123456)
"\x81\x21\x43\x65\x87\xF7",6
however, in the first case,
the F7 should be
"\x81\x21\x43\xF5",4
and in the second
"\x10\x21\x43\x65\xFF",5
ie.. the F7 and first field are wrong.. but at least the last digit is right!
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2002 05:03 AM
01-21-2002 05:03 AM
Re: script help: awk input string parsing
God, I hates awk!
(Does it really mean awkward?)
RET = `echo $1 | awk '
{
stmp="\""
tmp=$1
olenoftmp=length(tmp)
if ( ( olenoftmp % 2 ) != 0 ) {
stmp = sprintf("%s%s%sx81",stmp,"\\\\","\\\\")
} else {
stmp = sprintf("%s%s%sx10",stmp,"\\\\","\\\\")
}
if ( ( olenoftmp % 2 ) != 0 ) {tmp = tmp F }
lenoftmp=length(tmp) / 2
for (i = 1; i < lenoftmp+1 ; i++) {
stmp = sprintf("%s%s%sx%s%s",stmp,"\\\\","\\\\",substr(tmp,(i*2),1),substr(tmp,
(i*2)-1,1))
numb=sprintf("%s",i)
}
if ( ( olenoftmp % 2 ) != 0 ) {
stmp = sprintf("%sF\", %d",stmp,i)
} else {
stmp = sprintf("%s%sxFF\", %d",stmp,"\\\\",i+1)
}
printf stmp
}
'`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2002 05:21 AM
01-21-2002 05:21 AM
Solution{
stmp="\""
##stmp=sprintf("%s%s%sx%s",stmp,"\\\\","\\\\","81")
tmp=$1
olenoftmp=length(tmp)
if ( ( olenoftmp % 2 ) != 0 ) {tmp = "18" tmp "F"} else {tmp = "01" tmp}
lenoftmp=length(tmp) / 2
for (i = 1; i < lenoftmp+1 ; i++) {
stmp = sprintf("%s%s%sx%s%s",stmp,"\\\\","\\\\",substr(tmp,(i*2),1),substr(tmp,
(i*2)-1,1))
}
if ( ( olenoftmp % 2 ) == 0 ) {stmp = sprintf("%s%s%sxFF",stmp,"\\\\","\\\\")}
stmp = sprintf("%s\",%d",stmp,olenoftmp)
printf stmp
}
'`
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2002 05:35 AM
01-21-2002 05:35 AM
Re: script help: awk input string parsing
Well, how about this:
RTN=`echo $1 | awk '
{
stmp="\""
numx=0
tmp=$1
olenoftmp=length(tmp)
if ( ( olenoftmp % 2 ) != 0 ) {
tmp = "180" tmp "7F";
} else {
tmp = "01" tmp "FF";
}
lenoftmp=length(tmp) / 2
for (i = 1; i < lenoftmp+1 ; i++) {
stmp = sprintf("%s%s%sx%s%s",stmp,"\\\\","\\\\",substr(tmp,(i*2),1),substr(tmp,(i*2)-1,1))
numx++
}
stmp = sprintf("%s\",%d",stmp,numx)
printf stmp
}
' `
echo $RTN
Notice, I do all the prep work up front, and let the reversing take care of the rest.
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2002 10:14 AM
01-21-2002 10:14 AM
Re: script help: awk input string parsing
Is there any way to add a Shell variable amongst all that awk stuff...
ie, bang in a $HELLO in the middle of the awk .. where the HELLO was defined outside the awk... I feel a lot of `'\"$'s coming along ;)
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2002 10:22 AM
01-21-2002 10:22 AM
Re: script help: awk input string parsing
sure there is ( from "man awk" ):
ARGC The number of elements in the ARGV array.
ARGV An array of command line arguments, excluding options and the program argument numbered from zero to ARGC-1.
ENVIRON Array of environment variables; subscripts arenames. For example, if environment variable V=thing, ENVIRON["V"] produces thing.
So I guess you are looking for that ENVIRON array.
Hope this helps
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2002 10:27 AM
01-21-2002 10:27 AM
Re: script help: awk input string parsing
Do you mean this (?):
# echo "hello"|awk -v WHO=bill '{print $0,WHO}'
...or, alternately:
# echo "hello"|awk '{print $0,WHO}' WHO=bill
...of course, the literal string "bill" could be a $VARIABLE from the shell...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2002 11:30 AM
01-21-2002 11:30 AM
Re: script help: awk input string parsing
Maybe it's time to cross the road and learn "perl"??
#!/usr/local/bin/perl
#
$stmp = "\"";
$tmp = $ARGV[0];
$olenoftmp = length($tmp);
$Ptmp=$tmp;
if ( ( $olenoftmp % 2) == 0)
{ $tmp = '01' . $Ptmp . 'FF'; }
else
{ $tmp = '18' . $Ptmp . 'F'; }
$lenoftmp = length($tmp) / 2;
for ($i = 0; $i < $lenoftmp ; $i++) {
$Ptmp=$stmp;
$stmp = sprintf('%s\\x%s%s', $Ptmp,
substr($tmp,($i * 2) + 1, 1), substr($tmp, ($i * 2), 1));
}
$stmp .= "\"," . $olenoftmp;
printf("%s\n",$stmp);
live free or die
harry