problem handling lov in FOR loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem handling lov in FOR loop
# 1  
Old 06-19-2012
problem handling lov in FOR loop

Hi all,

i am trying to process a list of values in FILE like this:

aaa:bbb
ccc:ddd
eee:fff

With the following logic:
Code:
for INFO in FILE
do
export F1=`cut -f1,3,5,7 -d":" < FILE`
export F2=`cut -f2,3,5,7 -d":" < FILE`
 
ssh $F1 bash <<EOF
 
echo $F1
echo $F2
date
EOF
done

The problem I am finding is that the cut is extracting ALL values in the first column of FILE and the script is erroring because the second row value is not being handled.

Is there anyway I can have the script process ie cut the first row in turn, do the ssh and then do the second row and third in turn?

Hope this is clear,

Thanks in advance for any help.

jd

Last edited by fpmurphy; 06-19-2012 at 09:58 AM.. Reason: code tags please
# 2  
Old 06-19-2012
problem hendling lov in FOR loop

Are trying to read the values separated by colon (Smilie into two different variables ? If so, you can use while loop to iterate throught the file and read the columns into variables using awk command:
Code:
var1=awk -F":" '{print $1)'  $inputLine
var2=awk -F":" '{print $2)'  $inputLine


Last edited by fpmurphy; 06-19-2012 at 09:59 AM..
# 3  
Old 06-19-2012
Explain in Details with output you want..
# 4  
Old 06-19-2012
so I have a file with values:
aaa:bbb
ccc:ddd
eee:fff


And the logic is thus:

for each row in turn,

ssh to host with first value of first row
echo second value of first row
exit
ssh to host with first value of second row
echo second value of second row
exit
ssh to host with first value of third row
echo second value of third row
exit
# 5  
Old 06-19-2012
Something like this:

Code:
oldIFS="$IFS"
IFS=':'
while read field1 field2
do
 echo $field1
 echo $field2
 #### something with the 2 fields ###
done < inputfile
IFS="$oldIFS"

# 6  
Old 06-19-2012
you are excepting this one...
Code:
awk -F ':' '{ print $1>"test1.txt"} {print $2>"test2.txt"}' test.txt

# 7  
Old 06-19-2012
getting confused..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with call of Java Programm & return code handling & output to several streams.

Hello Everybody, thanks in advance for spending some time in my problem. My problem is this: I want to call a java-Programm out of my shell skript, check if die return code is right, and split the output to the normal output and into a file. The following code doesn't work right, because in... (2 Replies)
Discussion started by: danifunny
2 Replies

2. Infrastructure Monitoring

Perl Error Handling Problem

I can get this working, but if something is down I get an error and the script does not move on. I can not get the "else" function working. What might I be doing wrong? use SNMP::Simple my %ios = (); $list="list.list"; open(DAT, $list) || die("Can't Open List"); @raw_data=<DAT>;... (4 Replies)
Discussion started by: mrlayance
4 Replies

3. Shell Programming and Scripting

Null Handling in Until loop. . .loop won't stop

Hi Im running this script, which is supposed to find the max value build some tables and then stop running once all the tables are built. Thing is , it keeps assigning a null value to $h and then $g is null so it keep building tables i.e. testupdateNUL. How can I stop this? Here is what I have: ... (4 Replies)
Discussion started by: brandono66
4 Replies

4. Programming

problem in reforking and signal handling

hi friends i have a problem in signal handling ... let me explain my problem clearly.. i have four process .. main process forks two child process and each child process again forks another new process respectively... the problem is whenever i kill the child process it is reforking and the... (2 Replies)
Discussion started by: senvenugopal
2 Replies

5. Programming

problem in SIGSEGV signal handling

i wrote handler for sigsegv such that i can allocate memory for a variable to which sigsegv generated for illlegal acces of memory. my code is #include <signal.h> #include<stdio.h> #include<stdlib.h> #include<string.h> char *j; void segv_handler(int dummy) { j=(char *)malloc(10); ... (4 Replies)
Discussion started by: pavan6754
4 Replies

6. Shell Programming and Scripting

String handling is not working inside if loop

Hi All, I am comparing two strings inside an if condition if the strings are same then it should go inside the loop else it should execute code given in else part. But there is a but inside my script Even if the if condition is true it is not going inside the loop also it is executing... (4 Replies)
Discussion started by: usha rao
4 Replies

7. Shell Programming and Scripting

Problem with awk while handling special charaters

Hi, I have an application.xml file like </dependency> <artifactId>_AdminServicesEAR</artifactId> <version>1.0.0-20080521.085352-1</version> <context-root>oldvalue</context-root> <type>ear</type> <DOCTYPE "abc/xyz/eft"> <NewTag>value123</xyz> ... (4 Replies)
Discussion started by: subin_bala
4 Replies

8. Programming

Problem with handling SIGINT

For a program I am designing, which involves handling the keyboard input Ctrl^c (SIGINT), it is taking ages for the program to actually recognise and perform the corresponding action whenever I run it and hit Ctrl^C at the CL. I have to do at least 3 Ctrl^Cs before the program will actually... (3 Replies)
Discussion started by: JamesGoh
3 Replies

9. UNIX for Dummies Questions & Answers

file handling problem in perl......

Hi, I am opening a file......then i am wrting some data into it......and i am reopening the file again but ......i get a error cannot open file....... $::file= "\adder\testfile.txt" open(TEST1,$::file); some write operation close(TEST1) open(TEST1,$::file) 'I GET A ERROR CAN OPEN... (2 Replies)
Discussion started by: vivekshankar
2 Replies

10. HP-UX

Inter Process File Handling Problem

Hi All, i am running a oracle procedure which writes a file . The same file is picked up by another script which runs in a cron after every 5 minutes. Now the problem is that sometimes my script picks up a file while the procedure is still writing data in the file. is there is any way i... (4 Replies)
Discussion started by: saurabhjain
4 Replies
Login or Register to Ask a Question