Greping the required parameter...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Greping the required parameter...
# 1  
Old 04-01-2008
CPU & Memory Greping the required parameter...

Hi Friends,
Urgently required to know this :

I have a file which has several stanzas like below :
CuDv:
name = "hdisk3"
status = 1
chgstatus = 2
ddins = "scdisk"
location = "03-08-01-11,0"
parent = "scsi1"
connwhere = "11,0"
PdDvLn = "disk/scsi/scsd"

CuDv:
name = "hdisk2"
status = 1
chgstatus = 2
ddins = "scdisk"
location = "03-08-01-11,0"
parent = "scsi0"
connwhere = "11,0"
PdDvLn = "disk/scsi/scsd"




My question is : How can one get the field specified in the"name"( In this case hdisk3 of 1st stanza) if "parent=scsi1" ?

Thanks is advance..
# 2  
Old 04-01-2008
Pedestrian solution: awk script to remember the name it has seen last, and print it when it sees the right parent. Forget the previous name when you see an empty line.

Slightly more advanced: perl has a way to read multiple lines; if you know the basics of the language, looking for $/ in examples and in the FAQ should be enough for you.

Enterprise solution: hire an incompetent consultant to write 67 Java classes which altogether fail to correctly parse this file format.
# 3  
Old 04-01-2008
Code:
awk 'BEGIN{FS="="}
/name =/ { d=$2 }
/parent = \"scsi1\"/ { print d}
' file

# 4  
Old 04-02-2008
Code:
nawk 'BEGIN{FS="";RS="CuDv:"}
{
if(index($7,"scsi0")!=0)
print substr($2,index($2,"\"")+1,length($2)-index($2,"\"")-1)
}' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Best Alternative for checking input parameter contains required value or not

Any good way to check if code has the required output # /sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts net.ipv4.icmp_echo_ignore_broadcasts = 1 /sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "= 1" net.ipv4.icmp_echo_ignore_broadcasts = 1 What I can think of is above, and it... (16 Replies)
Discussion started by: alvinoo
16 Replies

2. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

3. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

4. Shell Programming and Scripting

need help in greping

Hi, i have to find a string in a file and positin of the string in the file would come in some particular interval. let's say file is 1-1000 lines and string is in from 200-300line. could any one suggest me how to get make the grep search for the string in that particular portion of the... (4 Replies)
Discussion started by: tarakant
4 Replies

5. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

6. Shell Programming and Scripting

need help in greping

i have a ksh script : #!/bin/ksh TZ=`date +%Z`+24 ;a=`date +%Y-%m-%d` b=`date +"%H:%M:%S"` cd /ednadtu3/u01/pipe/logs for i in Archiver1.log do cat $i | grep $a | grep $b >> /ednadtu3/u01/pipe/naveed/Insert_Date.txt done... (4 Replies)
Discussion started by: ali560045
4 Replies

7. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 Replies

8. Shell Programming and Scripting

Help required to pass the parameter

i am calling a pl/sql procedure through a shell script, there is one IN and 2 OUT parameter required to pass to the procedure to execute.. My procedure is XX_CITIDIRECT_EXP_PKG.main_proc and In parameter is p_period which I wanto to pass 'MAY-06'. Can anyone figure out, whats is wrong here ... (4 Replies)
Discussion started by: u263066
4 Replies

9. Shell Programming and Scripting

Greping certain lines

One of my outout is like this as shown below. How can I grep only the lines after the line "Affected files ...". No of lines after the line "Affected files ..." may vary. $ cat file_A Change 149133 by csaha@test_depo_csaha on 2006/02/08 01:40:57 *pending* This is to test change #... (5 Replies)
Discussion started by: csaha
5 Replies

10. UNIX for Dummies Questions & Answers

GREPing for Nulls

I just had a filesystem / file corruption issue on my HSP's server due to disk capacity limits and fileswapping. I discovered that certain files got corrupted when fileswapping was not successful and they ended up with a string of control characters, or what I believe to be nulls, in them. Does... (4 Replies)
Discussion started by: Dr. DOT
4 Replies
Login or Register to Ask a Question