Execution Problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution Problems
# 1  
Old 12-05-2011
Debian Modify my script "wanna add a feature"

this my source file
Code:
************* fixed  ***************
Begin  

equipmentId : d9
processor : fox
number : bhhhhhh


Variable # 1: 
  
Id           : 100
Type         : 9
nType        : s
gType        : 5f
mType        : 4
LField       : England
DataField    : london
Length       : 4

 End 


Variable # 2: 
  
Id           : 200
Type         : 9
nType        : f
gType        : f
mType        : 9
LField       : England
DataField    : london
Length       : 4

 End 


Variable # 3: 
  
Id           : 400
Type         : 7
nType        : c
gType        : r
mType        : h
LField       : Egypt
DataField    : Cairo
Length       : 4

 End 

Variable # 4: 
  
Id           : 515
Type         : 7
nType        : 1
gType        : 5d
mType        : 9a
LField       : France
DataField    : Paris
Length       : 2

 End 


End of  section.

************* fixed  ***************

Begin 

equipmentId : d9
processor : fox
number : bhhhhhh


Variable # 1: 
  
Id           : 515
Type         : 9
nType        : s
gType        : 5f
mType        : 4
LField       : England
DataField    : london
Length       : 4

 End 

Variable # 2: 
  
Id           : 550
Type         : 9
nType        : f
gType        : f
mType        : 9
LField       : France
DataField    : Paris
Length       : 4

 End


Variable # 3: 
  
Id           : 600
Type         : 7
nType        : c
gType        : r
mType        : h
LField       : Egypt
DataField    : Cairo
Length       : 4

 End  
  
End of  section.

************* fixed  ***************

Begin  

equipmentId : d9
processor : fox
number : bhhhhhh


Variable # 1: 
  
Id           : 100
Type         : 9
nType        : s
gType        : 5f
mType        : 4
LField       : England
DataField    : london
Length       : 4

 End 

Variable # 2: 
  
Id           : 516
Type         : 9
nType        : f
gType        : f
mType        : 9
LField       : Egypt
DataField    : Cairo
Length       : 4

 End 

Variable # 3: 
  
Id           : 609
Type         : 7
nType        : c
gType        : r
mType        : h
LField       : usa
DataField    : NY
Length       : 4

 End
  

Variable # 4: 
  
Id           : 715
Type         : 7
nType        : 1
gType        : 5d
mType        : 9a
LField       : germany
DataField    : munich
Length       : 2

 End 

End of  section.
************* fixed  ***************

Begin  

equipmentId : d9
processor : fox
number : bhhhhhh


Variable # 1: 
  
Id           : 100
Type         : 9
nType        : s
gType        : 5f
mType        : 4
LField       : England
DataField    : london
Length       : 4

 End 

End of section.

i`ve asked get a column getting ( DataField under ID : 515 or 516 ) in the variable part that its not in same place every time and variable fields are not of a fixed number and if he couldnt find ID 515 nor 516 return with ( not found )
thats mean our output
Code:
Paris 
london 
cairo 
not found   ....... as Id 515 not found nor 516

Chubler_xl got me this

Code:
nawk -v target=${1:-515} '
    $1 == "End" && $2 == "of" {
        if( value["Id"] == target )
            print value["DataField"];
        else print "Not Found";
        split( "", value, "." );
    }
    $1 == "End" {snarf=0; next }
    $1 == "Id" && $3 == target { snarf=1 }
    snarf && $2 == ":" {value[$1] = $3}
' infile

this gets mee only id = 515 what if [ 516 and 515 ]
i tried to make it but nothing done please help as fast as possible Smilie

Last edited by teefa; 12-05-2011 at 05:47 PM..
# 2  
Old 12-05-2011
So it needs to find both in the same section, or else print 'not found'?

Or is it okay if the section only contains some of them?
# 3  
Old 12-05-2011
no the section will contain either one of them ( either 516 or 515 ) not both in same section
if finds one of them get the data field of it in both one column if not prints " not found "
# 4  
Old 12-05-2011
How about this:

Code:
awk -v target=${1:-515|516} '
    $1 == "End" && $2 == "of" {
        if( match(value["Id"], target))
            print value["DataField"];
                else print "Not Found";
                split( "", value, "." );
    }
    $1 == "End" {snarf=0; next }
        $1 == "Id" && $3 == target { snarf=1 }
    snarf && $2 == ":" {value[$1] = $3}
' infile

# 5  
Old 12-05-2011
thanks for your reply
1) it doesnt work with (awk) it will work with (nawk)

2) when i do it with nawk the output all is not found

can u handle it again
# 6  
Old 12-05-2011
Sorry should test before I post, this is what you want:
Code:
awk -v target="${1:-515|516}" '
    $1 == "End" && $2 == "of" {
        if( value["Id"] ~ target )
            print value["DataField"];
                else print "Not Found";
                split( "", value, "." );
    }
    $1 == "End" {snarf=0; next }
        $1 == "Id" && $3 ~ target { snarf=1 }
    snarf && $2 == ":" {value[$1] = $3}
' infile

This User Gave Thanks to Chubler_XL For This Post:
# 7  
Old 12-05-2011
thanks alot Smilie
merci
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Execution problems

How to find a word in a directory which contains many files? i just want to count how many such words are present in all the files? This is the code which i tried for a single file echo "Enter the file name:" read file echo "Enter the word to search:" read word if then echo "The count... (4 Replies)
Discussion started by: Meeran Rizvi
4 Replies

2. UNIX for Dummies Questions & Answers

Execution Problems with Crons

Buddies, cron is not executing any monitoring scripts for 'Oracle' user in Red Hat Linux 5. Details about the cron job :- oracle@localhost ~]$ crontab -l 15 7 * * * /home/oracle/tab.sh The tab.sh script when firing manually is working fine. Any inputs/advice will be great for me. (12 Replies)
Discussion started by: sandip250382
12 Replies

3. Shell Programming and Scripting

Execution problems with sed

Hi,I confused how to use sed to deal with big file. example: the big file have some different urls just with filename. how can i use sed to fetch url except file name and replace to other urls with filename? thanks!!! (11 Replies)
Discussion started by: hshzh359
11 Replies

4. Solaris

Execution problems with Mailx

Unable to send mail using mailx command. I am using solaris 5.9 I am trying to send notification for the scheduled jobs in crob but the mailx is not working. Checked the settings in submit.cf and sendmail.cf but unable to find the solution. Error message root@sshldb # nslookup mailhost... (8 Replies)
Discussion started by: Srinathkiru
8 Replies

5. Shell Programming and Scripting

Execution problems with scripting

Hi, I am new to scripting.I had one problem infront of me.I tried in many ways with minimal knowledge........Kindly help me. Description: I want a shell script where it has to read an input.txt file and need to remove duplicate lines and the result need to kept in output.txt file. input... (5 Replies)
Discussion started by: bhas
5 Replies

6. Shell Programming and Scripting

Execution Problems with if statements

Hi all, I habe a file called test.log, which contain following data : 0.0 0.1 0.1 0.1 0.1 0.2 0.3 0.3 0.4 0.4 0.6 8.7 8.8 17.2 I want to show the data which gater than 9.0 But my script not working. (4 Replies)
Discussion started by: mnmonu
4 Replies

7. Homework & Coursework Questions

Execution Problems with sed

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Okay so I am taking bash scripting this semester and we are now working on the stream editor sed. For our book we... (4 Replies)
Discussion started by: aggie6970
4 Replies

8. Shell Programming and Scripting

Execution Problems!!

i have been working on this for a about 12 hours today say's end of file un expected any idea's using the bourne shell and its driving me nuts worked fine in bash but prof says make it work in bourne and good luck worth 13% any help would be awesome #!/bin/sh trap "rm mnt2/source/tmp/* 2>... (1 Reply)
Discussion started by: mrhiab
1 Replies

9. Programming

execution problems with cron

how to store a date into file? and how we can access date from the file? ---------- Post updated at 06:09 AM ---------- Previous update was at 06:08 AM ---------- how we can store date in file? (1 Reply)
Discussion started by: causalmodi777
1 Replies

10. Shell Programming and Scripting

execution problems with curl

I have been getting error "curl: (7) Failed to connect to IP number 1" when using the CURL command Could someone help??? (1 Reply)
Discussion started by: infernalhell
1 Replies
Login or Register to Ask a Question