FOR loop problem: Kindly Help


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
FOR loop problem: Kindly Help

Hello Friends,

I have file called reference.txt which looks like below,

Quote:
wahabeua |3.1 |wahabeua-1.1.11 |Not available |Code Coverage
ferrari12 |4.0 |ferrari12-1.1.21|Not applicable |Code Coverage
masterpiece |4.1 |masterpiece-2.2.33 |File Changes |Code Coverage
columns are been formed by delimiter "|" as shown. I am required to scan whole file line by line & compare 1st 2 columns with new name (ex. ferrari) & new version (2.1).

CODE PURPOSE: whnever new project formed compare if it already exists & compare if version updated.

My Code
Quote:
for file in $(cat reference.txt);do
if [[ `echo $file | cut -d ',' -f1` == $PROJECT ]];then
echo "Project Matched"
if [[ `echo $file | cut -d ',' -f2` == $VERSION ]];then
echo "Project & Version Matched"
else
echo "Project Matched but Version Revised"
fi
else
echo "Complete New Project"
fi
echo "$n"
let "n += 1"
done
By executing my code i am finding,
1. its looping for 19 times instead of looping for only 3 times. & providing 3 output for 3 rows.

Kindly help. Thanks a lot.

Last edited by okdev; 10-04-2007 at 09:55 PM..
# 2  
Perhaps try something like this....
Code:
oldIFS="$IFS"
IFS='|'
while read f1 f2 etc
do
   echo do something with $f1 and $f2
done < reference.txt
IFS="$oldIFS"

# 3  
Thanks But Keep in touch

Sir thanks a lot for this quick solution. It absolutely gonna help. But stay connected.. if i need some more help!!!

Smilie

Thanks
# 4  
Continuation Problem

Once i find PROJECT matched & project VERSION matched. I am supposed to update $f3 & $f4 (3rd & 4th field) of same file.

Example:
reference.txt
Quote:
wahabeua |3.1 |wahabeua-1.1.11 |Not available |Code Coverage
ferrari12 |4.0 |ferrari12-1.1.21|Not applicable |Code Coverage
masterpiece |4.1 |masterpiece-2.2.33 |File Changes |Code Coverage
New Project with following variables (I have)
Quote:
PROJECT=ferrari12
VERSION=4.0
LABLE=ferrari12-1.1.25
Reference.txt should look like follwing.

Quote:
wahabeua |3.1 |wahabeua-1.1.11 |Not available |Code Coverage
ferrari12 |4.0 |ferrari12-1.1.25|Not applicable |Code Coverage
masterpiece |4.1 |masterpiece-2.2.33 |File Changes |Code Coverage
Code:
Quote:
#!/bin/sh

PROJECT=ferrari12
VERSION=4.0
LABLE=ferrari12-1.1.25

n=1 # Line Number

oldIFS="$IFS"
IFS='|'
while read f1 f2 f3 etc
do
if [ $f1 == $PROJECT ];then
echo "Line $n: Project Matched"
if [ $f2 == $VERSION ];then
echo " Version Matched"
sed 's/$f3/$LABLE/' # Lable Replaced
else
echo " Version Not Matched"
fi
else
echo "Line $n: New Project"
fi
let "n += 1"
done < reference.txt
IFS="$oldIFS"
some how sed is not working for me there to replace lable. Do you have some logic to fit in this loop.

Please Help! Thanks Smilie
# 5  
People Kindly Help

People Please Help me out.
ThanksSmilie
# 6  
Hi.

Use double quotes in this situation -- single quotes do not allow variable expansion:
Code:
sed 's/$f3/$LABLE/' # Lable Replaced

I suggest you look over some tutorials like BASH Programming - Introduction HOW-TO ... cheers, drl
# 7  
sed "s/$f3/$LABle/"


cheers,
Devaraj Takhellambam
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #374
Difficulty: Easy
In 2004, a new edition of the POSIX:2002 standard was released called POSIX:2004 (formally: IEEE Std 1003.1-2004).
True or False?

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Kindly Help regarding sorting a file rows

Dear All, I have a file name exporting.txt. Below is the content. $ cat exporting.txt . . exporting table DT_BCD 63716 rows exported . . exporting table DT_CVD 36321 ... (2 Replies)
Discussion started by: sudiptabhaskar
2 Replies

2. Post Here to Contact Site Administrators and Moderators

kindly move thread

kindly move this thread: https://www.unix.com/unix-dummies-questions-answers/176868-get-all-strings-after-equal-sign.html to Shell Programming and Scripting...created in wrong forum... thanks!!! (0 Replies)
Discussion started by: h0ujun
0 Replies

3. Solaris

CJS instalation one problem...kindly help

hi am installing CJS frm one server to a cleint and i first did ./add_install_client -e now i need to know the mac add of the client so i entered into client and now hopw can i go to ok prmt ^] when this symbol is entered am nt being able to enter to ok promt what to do i... (1 Reply)
Discussion started by: all_is_well
1 Replies

4. Shell Programming and Scripting

kindly help me out on this please

Hello experts, please help me on this. This is the scenario: I have applications like BigBrother,PowerKeeper/PowerBroker etc.. which I have to install during server build for both AIX and Solaris. I already have separate installation scripts for both OS for all applications. Now, I want to... (0 Replies)
Discussion started by: solaix14
0 Replies

5. Shell Programming and Scripting

Kindly help : sort

Iam new to Unix ....analyzing the code Can any one pls explain what does it mean by below code sort +0 -1 +1 -2 +2 -3n +3 -4n +4 -5n file.txt -o awaiting for reply ..... (1 Reply)
Discussion started by: charandevu
1 Replies

6. Shell Programming and Scripting

comparing 2 files - kindly assist expert

Hi, I'm new in shell scripting and would like u guys to help on this. OS: Solaris 9 currently, i have 2 files. file1: hello hi test god file2: hi hello file1 is my masterfile, and i wanted to print out string that are in file1 and NOT in file2 and send out a mail (with the... (15 Replies)
Discussion started by: chew
15 Replies

7. Shell Programming and Scripting

Can someone kindly help with appending problem!!!

Hi guys,i urgently need help in this problem,i need to append one sentence to another line when it meet a certain word. For example: root: root time_last_login = 1191232080 root tty_last_login = /dev/vty0 root host_last_login = rep1nim root unsuccessful_login_count = 0 root... (10 Replies)
Discussion started by: cyberray
10 Replies

Featured Tech Videos