- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Echo and foreach loop problem
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-06-2005 09:03 PM
02-06-2005 09:03 PM
I have the following script
#!/bin/csh
set imsi=`grep IMSI test.out | awk '{print $3}'`
foreach ki (sed -n 'var_out/,p' test.out | sed '1,2d' | awk '{print $7}'`)
echo "ZMAC:IMSI=${imsi}":KI="$ki",UV=50"
end
The first line while produce
imsi1
and
for 2nd line will produde :=
ki1
ki2
ki3
ki4
and i was try to get the output using echo as :=
ZMAC:IMSI=imsi1":KI=ki1,UV=50;
ZMAC:IMSI=imsi1":KI=ki2,UV=50;
ZMAC:IMSI=imsi1":KI=ki3,UV=50;
But the above script only give me :=
:KI=ki1,UV=50;
:KI=ki2,UV=50;
:KI=ki3,UV=50;
with the missing 1st parameter.
Where did i go wrong?
Thanks in advance.
You guys are great!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2005 09:39 PM
02-06-2005 09:39 PM
Re: Echo and foreach loop problem
too many quotes
try
echo "ZMAC:IMSI=${imsi}:KI=${ki},UV=50"
instead of
echo "ZMAC:IMSI=${imsi}":KI="$ki",UV=50"
regards,
Thierry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2005 11:13 PM
02-06-2005 11:13 PM
Re: Echo and foreach loop problem
Or you can use:
echo "ZMAC:IMSI="${imsi}":KI="$ki",UV=50"
to create new subscribers.
Regards,
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2005 01:31 PM
02-07-2005 01:31 PM
Re: Echo and foreach loop problem
Thanks but both of the solution seems not working for me.
The output is still
:KI=ki1,UV=50;
:KI=ki2,UV=50;
:KI=ki3,UV=50;
Hmm..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2005 04:10 PM
02-07-2005 04:10 PM
Re: Echo and foreach loop problem
Please do not retype... just cut & paste!
It would help to have a small 'test.out' attache to try on.
This works on my SuSe 9 box:
#!/bin/csh
set imsi=`grep IMSI test.out | awk '{print $3}'`
foreach ki (`sed -n "/var_out/p" test.out | sed "1,2d" | awk '{print $7}'`)
echo "ZMAC:IMSI=${imsi}":KI="$ki",UV=50
end
----- input ----
IMSI xxx imsi1
a var_out c d e f ki5 x x
a var_out c d e f ki6 x x
a var_out c d e f ki7 x x
a var_out c d e f ki8 x x
a b c d e f ki1 x x
a var_out c d e f ki2 x x
a b var_out d e f ki3 x x
a b c var_out e f ki4 x x
a b c d e f ki5 x x
------ output -------
ZMAC:IMSI=imsi1:KI=ki7,UV=50
ZMAC:IMSI=imsi1:KI=ki8,UV=50
ZMAC:IMSI=imsi1:KI=ki2,UV=50
ZMAC:IMSI=imsi1:KI=ki3,UV=50
ZMAC:IMSI=imsi1:KI=ki4,UV=50
The following perl 'one-liner' gives the same output. The only assumption is the the line with IMSI comes before var_out. Does it?
perl -ne '$imsi=(split)[2] if /IMSI/; print "ZMAC:IMSI=${imsi}:KI=".(split)[6].",UV=50\n" if (/var_out/ && ($i++ > 1))' est.out
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2005 08:10 PM
02-07-2005 08:10 PM
Re: Echo and foreach loop problem
This is a sample of test.out
----------
Transport_key: 2
A3_Type: 04
PPD_srn :
Quantity: 80
Type: Plug-in
Profile:
Batch: SIMT101
SIM_Reference: USIM_TEST
HLR: 1
Location: WM
013/019: 013
Graph_ref:
var_in_list:
Ser_nb: 896017363050170155364
IMSI : 5021313872800000096
var_out: PUK/PIN/PIN2/PUK2/KI/ADM1
8960130501701553643F 502131300000096 11111111 1234 1234 22222222 11111111111111111111111111111111 12345678
8960130501701553650F 502131300000097 11111111 1234 1234 22222222 11111111111111111111111111111111 12345678
8960130501701553668F 502131300000098 11111111 1234 1234 22222222 11111111111111111111111111111111 12345678
-------------------------------
I have tried with this
#!/bin/csh
set imsi=`grep IMSI test.out | awk '{print $3}'`
foreach ki (sed -n 'var_out/,p' test.out | sed '1,2d' | awk '{print $7}'`)
echo "ZMAC:IMSI=${imsi}:KI=$ki,UV=50"
end
------------------
But the result was half of the command in multiple line - first half missing.
:KI=11111111111111111111111111111111,UV=50
:KI=11111111111111111111111111111111,UV=50
:KI=11111111111111111111111111111111,UV=50
:KI=11111111111111111111111111111111,UV=50
:KI=11111111111111111111111111111111,UV=50
But say I replace ${imsi} with a UNIX command such as `date` it work as it supposed to.
Where did I go wrong ?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2005 08:17 PM
02-07-2005 08:17 PM
Re: Echo and foreach loop problem
Try not to use the /bin/csh but the /bin/sh.
csh has to many options, versions and implementations.
use
!#/bin/sh
Regards,
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2005 08:25 PM
02-07-2005 08:25 PM
Re: Echo and foreach loop problem
I will try that very soon. Its a long holiday here for the Chinese New Year- so no access to my system yet.
Thanks :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2005 08:30 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2005 12:15 AM
02-08-2005 12:15 AM
Re: Echo and foreach loop problem
The script you post is riddled with typos.
To avoid confusion please only cut&paste. Do not re-type.
There is a missing open back-tick before 'sed'
There is a missing open slash for the sed pattern
There is a missing closing match ($) on that pattern.
This works for me:
set imsi=`grep IMSI test.out | awk '{print $3}'`
foreach ki (`sed -n '/var_out/,$p' test.out | sed '1,2d' | awk '{print $7}'`)
echo ZMAC:IMSI=${imsi}:KI=$ki,UV=50
end
Now just cut & past that!
This perl one line also works:
perl -ne '$imsi=(split)[2] if /IMSI/; $data=1 if /var_out/; print "ZMAC:IMSI=${imsi}:KI=".(split)[6].",UV=50\n" if ($data && ($i++ > 1))' test.out
But if you wrote it in perl you'd probably want to add more security for example:
$field = "KI";
while (<>) {
last if ($field_index);
$imsi=$1 if (/IMSI\s*:\s*(\S+)/);
if (/var_out/) {
@words = split("/");
while ($x = $words[$i++]) {
if ($x eq $field) {
$field_index = ++$i;
last;
}
}
}
}
die "No field $field found on line with var_out" unless $field_index;
while (<>) {
print "ZMAC:IMSI=$imsi:$field=".(split)[$field_index].",UV=50\n";
}
This will pick up the 'imsi' value with or without spaces around that colon.
And it will determine the right column for the select field from the var_out line.
(Admittedly, the way is skips the blank line is a hack :-).
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2005 02:15 AM
02-08-2005 02:15 AM
Re: Echo and foreach loop problem
i found error with "foreach" statement so i used "for"
#!/bin/csh -f
imsi=`grep IMSI test.out | awk '{print $3}'`
PI=`sed -n '/var_out/,/^$/p' test.out | awk '{ print $7}'`
for ki in $PI
do
echo "ZMAC:IMSI=${imsi}:KI=${ki},UV=50"
done
and the printout is :
ZMAC:IMSI=5021313872800000096:PI=11111111111111111111111111111111,UV=50
ZMAC:IMSI=5021313872800000096:PI=11111111111111111111111111111111,UV=50
ZMAC:IMSI=5021313872800000096:PI=11111111111111111111111111111111,UV=50
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2005 07:03 PM
02-13-2005 07:03 PM
Re: Echo and foreach loop problem
I manage to get it works now. As advised by Hein, I cut and paste the script from here and it works now.
Thanks a lot.
You guys are really great!