- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk Help (functions)
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
08-24-2004 06:40 PM
08-24-2004 06:40 PM
Awk Help (functions)
To explain what I am trying to achive is firstly I read my input file, get a filename (SEA="*/*/*"$6"."$7"*"$8"*") and then search for that file.
Once the file is found, I call a tool (system function (which), in-order to read it in text (HEXtoTEXT) and this is when I get stuck.
Using a for loop function, search for that number ($1 or $2 if it is b_num) and print the result(s)
I tried the following but no luck
{while ( ( getline < "system(TOOL2" "FILE)" ) > 0 )
{for(e=1;e
print $0}
close("system(TOOL2" "FILE)")
TOOL2 being the tool used to read the file (FILE)
My script:
awk -v NUM=b_num '
function get_f_name(file) {
e_a="NumberReceived]5"
e_b="NumberReceived]5"
e_e=$(e+4)
gsub("^0","",$1)
SEA="*/*/*"$6"."$7"*"$8"*"
{if (match($7,"df23")){
TOOL="/usr/bin/which chris_s "
TOOL | getline TOOL2;close(TOOL)
}
}
{if(system("/sbin/ls -rt " SEA ) != 0) {
#{if(system("/usr/bin/test -r " SEA ) != 0) {
print ("Failed!!!");
}else{
print ("GOOD");
tool="/sbin/ls -rt " SEA
tool | getline RES ;close(tool)
while ( ( getline < "system(TOOL2" "RES)" ) > 0 ) <---- This is where I get stuck
{for(e=1;e
getline
print $0
}}}}
close("system(TOOL2" "RES)")
}}
{if ($0~/[a-z,+]:/){
SEA="*/*/*"$6"."$7"*"$8"*"
NUM1=$1
printf "%15s %15s %15s %15s %15s %s\n",$1,$2,$3,$4,$5/10,SEA
{if(NUM~/a_num/){
print (NUM)
get_a_name()
}else{
if(NUM~/b_num/){
print (NUM)
get_b_name()
}else{
if(NUM~/c_num/){
print (NUM)
get_c_name()
}}}}}
}' Chris_num
and my input file looks like this
011111111 20040814092402 2222222 1 1140 tedo:04 df23 403866 )
If there is a different way with awk, I am eager to learn.
Regards
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2004 07:03 PM
08-24-2004 07:03 PM
Re: Awk Help (functions)
system command on awk program only returns the exit status of executed command.
And more input file contents 011111111 20040814092402 2222222 1 1140 tedo:04 df23 403866 are not being enough to look in to the script and debug for the problem.
As easy why do n't you do the shell operations in the shell script and execute on awk program simply. But your script seems to be hard to lookup. :)
If you give input file full informations and what you are expecting from the input to final output then that will make responder(S) to give their own and good idea too.
Regards
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2004 07:36 PM
08-24-2004 07:36 PM
Re: Awk Help (functions)
Thanks for your responce.
I agree with u that in a simple script it will do the trick, I know awk will do it faster.
Could I maybe explain in a different way.
=================================
function get_f_name(file) {
=================================
e_a="NumberReceived]5"
e_b="NumberReceived]5"
e_e=$(e+4)
gsub("^0","",$1)
SEA="*/*/*"$6"."$7"*"$8"*"
{if (match($7,"df23")){
TOOL="/usr/bin/which chris_s "
TOOL | getline TOOL2;close(TOOL)
}
}
{if(system("/sbin/ls -rt " SEA ) != 0){
print ("Failed!!!")
}else{
print ("GOOD");
tool="/sbin/ls -rt " SEA
tool | getline RES ;close(tool)
while ( ( getline < "system (TOOL2" "RES)" ) > 0 ) <---- This is where I get stuck
{for(e=1;e
getline
print $0
}
}
}
}
close("system(TOOL2" "RES)")
}
}
I have no problem in calling a system function as it works and also finding the file.
Once the file is found, I read it with a tool (called by a system function, which works), converts it from text to hex
with no problems. My dificult part is ,while reading the file, use a for loop to search for a specific number at a specific
place by using the variables (e_a="NumberReceived]5" etc). Can this be done and how???????
Many Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2004 07:50 PM
08-24-2004 07:50 PM
Re: Awk Help (functions)
To add additional info
My input file
A_NUM DATE B_NUM U DUR FILENAME
=========================================================
.011111111 20040814092402 2222222 1 1140 tedo:04 df23 403866
and the result should look like this
011111111 20040814092402 2222222 1 1140 tedo:04 df23 403866
DB-sub=1 39 [BasicInfo1]1 17 01 0227 092402 000089 000001 03 FF 02 01 02 [CallParty]2 9 01 0A 01 03 11111111F [NumberReceived]5 7 01 02 2222222
Regards
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2004 10:12 PM
08-24-2004 10:12 PM
Re: Awk Help (functions)
we can make the input file to output files easily but is there any relation between them ( common pattern ?!? )
I can make
A_NUM DATE B_NUM U DUR FILENAME
=========================================================
.011111111 20040814092402 2222222 1 1140 tedo:04 df23 403866
input lines to ouput first line of
011111111 20040814092402 2222222 1 1140 tedo:04 df23 403866
as,
sed -e 's/^\.//g' filename | grep '^[0-9]'
I see no relation on the second output line to input line. And even on your awk scripts too? IF we have come patterns and transformations it is very easy to translate it out.
It will be great and more helpful with the full input files and how the transformation of second output line happening so that to make scripts to do your requirement in a crisp manner.
I am only seeing the relation of 2222222 on 2nd line from input.
And more execution rate is not much differing on awk and as well as scripts.
Regards
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2004 11:11 PM
08-24-2004 11:11 PM
Re: Awk Help (functions)
Your markers could be something else if that's easier, of course.
For instance:
( echo "TOOL2" ; TOOL2 ; echo "INPUT" ; cat input ) | awk '
BEGIN {
/^TOOL2$/ { state='TOOL2';next }
/^INPUT$/ { state='INPUT';next }
state == 'TOOL2' {
state == 'INPUT' {
END {
'