What condition to be put in the while loop?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers What condition to be put in the while loop?
# 1  
Old 02-01-2008
Data What condition to be put in the while loop?

i have got a file where the env command is appended 5 times. i have to now look for the username and display it in the form of
1) PWD=/home/lee.ballancore
2) USER=lee.ballancore
3) MAIL=/var/spool/mail/lee.ballancore
4) LOGNAME=lee.ballancore
5) HOME=/home/lee.ballancore
6) PWD=/home/lee.ballancore
7) USER=lee.ballancore
8) MAIL=/var/spool/mail/lee.ballancore
9) LOGNAME=lee.ballancore
10) HOME=/home/lee.ballancore
in a new file. although the command for this is 'grep -h $USER <filename> which shows the correct output but i need to show the numbers 1,2,3 with the bracket everytime it finds an occurance. for this my sript is

echo "Enter the name of the file"
read file
int=1
while []
do
echo $int")" `grep -h $USER xx |more -1`
int=$(($int +1))
done

please can u tell me what condition can i put in the while command so that it prints the no along with the occurance.
# 2  
Old 02-15-2008
grep -hn ..............
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While Loop with if else condition

Hi, I was trying to write a shell script which reads csv file and sends mail in html format along with tables. Hope i have completed 1st part , but while sending mail i was trying to highlight some rows in the table based on the egrep outcome. If the string exists in line/INPUT, i am trying to... (4 Replies)
Discussion started by: varmas424
4 Replies

2. Shell Programming and Scripting

Put the appropriate value if reached the condition

i have a file as below: ? ? ? ? 20060101 DHR ? ? ? ? 20060101 1316 30.90 KOM ? ? ? ? 20060101 1317 7.20 DHR ? ? ? Pg ? 20060101 1316 27.32 DHR ? ? ? Sg ? 20060101 1316 30.52 ? ? ? ? 20060101 MRD ? ? ? ? 20060101 1355 46.12 SHB ? ? ? ? 20060101 1355 40.90 HSH ? ? ? Pn ?... (2 Replies)
Discussion started by: oreka18
2 Replies

3. Shell Programming and Scripting

Use of -z in while loop condition

Hi, Could you please tell what is the meaning of -z in while loop condition. For example, while ; do echo "*** Enter the age " readage (3 Replies)
Discussion started by: vidyaj
3 Replies

4. Shell Programming and Scripting

if condition in a while loop

Gurus, I need to read a line from a file and strip the characters from it and compare the stripped value with the value I pass to the script while executing it. Below is the code for the same. But when i execute the code, it is throwing an error. #!/bin/ksh . /home/.i_env ... (14 Replies)
Discussion started by: svajhala
14 Replies

5. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

6. Shell Programming and Scripting

Noob stuck - where do I put my loop

I'm a noob working on a script to take 3 user inputs. One of them is simply a variable: "poolname". The other 2 are cases: "groupa/groupb" and "enable/disable". "groupa" and "groupb" reference 2 files - groupa.txt or groupb.txt. These files simply consist of a list of server IP addresses and port... (2 Replies)
Discussion started by: *nixnoob
2 Replies

7. Shell Programming and Scripting

How to put html frames in for loop in perl?

Hi, I have to insert html frames in for loop. Here is the code. for($k=0;$k<3;$k++) { print<<HTML; <html> <head> <title> HTML Horizontal Frames </title> </head> <frameset cols="25%,75%"> <frame src="a.html"> <frame src="b.html"> </frameset> (0 Replies)
Discussion started by: vanitham
0 Replies

8. Shell Programming and Scripting

How to put for loop in nawk

Hello All, How i can put loop in nawk. what i want is that i define a variable which contain vlaues like var='1 2 3 4 5' and then define for loop which gives vlaue to nawk one by one to varilable inside nawk and then print it. cat /omp-data/logs/5etr/081121.APX | nawk -v CDNLIST='700 701' ' ... (1 Reply)
Discussion started by: wakhan
1 Replies

9. Shell Programming and Scripting

how can i put the condition in for loop for the below.

i have the equation like below 07:35:07 ( AB : 2319f.ab * 22) + ( AB : 2320f.ab * 22.03 ) + ( AB :2321f.ab * 22.07 ) ...... N i want put ":" as a delimiter and break the equation like below 2319f.ab * 22 2320f.ab *22.03 2321f.ab * 22.07 . . N i know the number of... (1 Reply)
Discussion started by: mail2sant
1 Replies

10. UNIX for Dummies Questions & Answers

Testing For Loop condition

How do I test the return condition in the script if no files are found: for file in `Find ${LANDING_FILE_DIR}${BTIME_FILENAME_PATTERN}` do ... .. done I want to capture the return code so I can echo the error or condition. Using if ] always returns zero no matter where it's placed. ... (4 Replies)
Discussion started by: mavsman
4 Replies
Login or Register to Ask a Question