Help on for loop with a parameter


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help on for loop with a parameter
# 1  
Old 05-08-2015
Help on for loop with a parameter

Hi,

need help to pass an paremeter to for loop script

Code:
 
$cat tp.ksh
 
for i in `grep $1 | cut -d "/" -f 5 | cut -d" " -f2`
do
fgrep $i $1 | grep 'with value' | cut -d "|" -f 2
done
 
$tp.ksh test_data.plan_49989_2015-05-01-00-13-38.log
 
command doesnot return the values.

Thanks in advance,
AAHinka

Last edited by AAHinka; 05-08-2015 at 10:13 AM.. Reason: typo
# 2  
Old 05-08-2015
Where does the $file variable get a value?
# 3  
Old 05-08-2015
What are you grep-ping for here grep $1 | ...?
This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 05-08-2015
Hello AAhinka,

Not sure about your complete requirement, but could you please try echo $1 in place of grep $1but this is a wild guess only, let us know the input with complete expected output, so that we can help you more on this.


Thanks,
R. Singh

Last edited by RavinderSingh13; 05-08-2015 at 10:31 AM..
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 05-08-2015
Hi,

i have tried with echo $1

Code:
 
$ cat > tp.ksh
echo $1
for i in `grep $1 | cut -d "/" -f 5 | cut -d" " -f2`
do
fgrep $i $1 | grep 'with value' | cut -d "|" -f 2 3
done

$ tp.ksh test_data.plan_49989_2015-05-01-00-13-38.log
test_data.plan_49989_2015-05-01-00-13-38.log

Script has no respone after above output,  .log is hughe log file i am trying to find some patterns.

Regards,
AAHinka
# 6  
Old 05-08-2015
grep $1 will wait forever for data from standard input.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass function parameter to do loop?

Hi All, I have created one function for KSH and was running well with one parameter input since I just had to use $1 to get the parameter. Now I want to do loop for each parameter(actually filenames) . I have try to use do loop, but $i does not resolve to parameter instead it resolves to 1,... (5 Replies)
Discussion started by: mysocks
5 Replies

2. Shell Programming and Scripting

Loop over awk or passing parameter

I wrote this script which works well when I manually input 55518622 and 1 but I need this script to be generic and loop over the following table awk '$4>(55518622-500000) && $4<(55518622+500000)' chr1_GEN2bim | awk 'BEGIN {min=1000000000; max=0;}; {\ if($4<min && $4 != "") min = $4; if($4>max... (8 Replies)
Discussion started by: fat
8 Replies

3. Shell Programming and Scripting

How to get the parameter value from the parameter file in perl?

hi all, i have a parameter file of following format, i want a method which can get the value of specific parameter. parameter file format: <Parameter Name="FileLocationWindows"> <Description> The directory location of the logger file. ... (1 Reply)
Discussion started by: laxmikant.hcl
1 Replies

4. Shell Programming and Scripting

Attempting to pass my array as a nested parameter to loop. A little lost.

I want to pass this array as a parameter. IFS=$'\n' fortune_lines=($(fortune | fold -w 30 )) Inside of this line screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say ${fortune_lines}\r"`" And I am lost at this point. I am thinking something like this? Then make it loop.. ... (7 Replies)
Discussion started by: briandanielz
7 Replies

5. 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

6. 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

7. UNIX for Dummies Questions & Answers

grep for a backslash as for loop parameter

Hello everyone, My main objective is to search for text within a file, namely a block of text where each line ends with a backslash "\". However, the block must begin with a keyword, like "loginstring". Here is an example of a file that contains a block: ############### loginstring \... (2 Replies)
Discussion started by: idlechatter
2 Replies

8. Shell Programming and Scripting

Problem if parameter has space in it using loop

for cmdopts in $*;do case $cmdopts in -mode) mode="$2";shift 2 ;; -server) server="$2";shift 2 ;; -Id) Id="$2";shift 2 ;; -passwd) passwd="$2";shift 2 ;; -rmtDir) rmtDir="$2";shift 2 ;; -lcDir) ... (9 Replies)
Discussion started by: pinnacle
9 Replies

9. Shell Programming and Scripting

Using the counter of a for loop in command line parameter

Say I have (in psuedocode) For i=1 to 10 tar cvfb /... 5*i /junk(i) end What I mean is that I want each successive for loop to have the block size parameter be 5 times the current counter. This isn't my actual code, just a stupid example...So the question is how do I descrive that parameter... (2 Replies)
Discussion started by: jeriryan87
2 Replies

10. 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
Login or Register to Ask a Question