Sponsored Content
Top Forums Shell Programming and Scripting Passing a value to a condition Post 302566641 by vgersh99 on Thursday 20th of October 2011 06:15:04 PM
Old 10-20-2011
You'll need to parse the file twice to get the right cube id when you encounter "<mtf>" - otherwise you're already late...
Something along these lines in awk - not as succinct as perl, but.....
nawk -f king.awk myFile
king.awk:
Code:
BEGIN{ ARGV[ARGC++] = ARGV[1] }
FNR==NR {if(/cube id=/ && match($0,"[0-9]+_")) {cubeA[++c]=substr($0, RSTART, RLENGTH-1);rs[c]=RSTART;rl[c]=RLENGTH}; next}
/mtf/ {
   printf("\t<portfolio>\n\t\t<directory>/tmp/%s<directory>\n\t</portfolio>\n", cubeA[++c2])
}
/cube id=/ {$0=substr($0,1,rs[c2]-1) substr($0, rs[c2]+rl[c2])}
1


Last edited by vgersh99; 10-20-2011 at 07:29 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

if condition ...

i have following if condition if above statement is case sensitive.....what is syntax if i have to make above comparision case insensetive (4 Replies)
Discussion started by: mahabunta
4 Replies

2. Shell Programming and Scripting

if condition

Hi friends, :) In a shell script i found the following if condition. echo -n "Which version of $1 do you want to restore ('0' to quit)? : " read desired if ${desired:=1} -ge $index ] ; then echo "$0: Restore canceled by user: index value too big." >&2 exit 1 fi Can... (1 Reply)
Discussion started by: ravi raj kumar
1 Replies

3. Shell Programming and Scripting

help with if condition

I do have a situation where , i need to zip the log files in the directory when the file exceeds more than 10MB. cd $ORACLE_HOME/network/log find . -type f -name "listener_*.log" > listeners Now i have all my *.log files listed in the listeners file So now i need to find the size of each... (5 Replies)
Discussion started by: naveen529
5 Replies

4. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

5. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

6. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

7. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

8. Shell Programming and Scripting

If condition

Please help me new to shell getting error while running below in shell script #!/bin/bash set -x cd /abc/def/ghi pwd xyz1=ghi if then FAILURE_TEMP="The ghi directory has not been properly defined for this server." echo ${FAILURE_TEMP} | /bin/mailx -s "apps copy failed"... (4 Replies)
Discussion started by: buzzme
4 Replies

9. Shell Programming and Scripting

Using if condition

Hello, I want to use if condition in an expression as below: $ORACLE_HOME is a variable something like below /oraprod04_01/app/oracle/product/10204 Now here it is product/10204 I want to check if $ORACLE_HOME has something which has a string like /product/10* then one statement should... (4 Replies)
Discussion started by: Vishal_dba
4 Replies

10. Shell Programming and Scripting

Help with if condition

o/p of my command is given below My requirement is if Pnumber is 0 then stabilization.Build.2013 else stabilization.PBuild.2013.3 (11 Replies)
Discussion started by: nikhil jain
11 Replies
All times are GMT -4. The time now is 05:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy