read a list one at a time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read a list one at a time
# 1  
Old 08-27-2006
Tools read a list one at a time

just have a muddled head at the moment... bare with me.

say i have a variable $count... and a list in a file

i want to use the $count line from that textfile but don't seem to recall how to access it?

eg

user=`cat file1.txt` # user to be $count line in that list?


eg

david
mark
james
kevin # want to extract mark as the $count variable

if someone could steer me to the right function I'd greatly appreciate the tip...
# 2  
Old 08-27-2006
Do you want the name mark to be extracted into the $count variable? A simple grep should do the trick.
Code:
count=$(grep "mark" file1.txt)

Remember that if you are using the original bourne shell, you will have to use `...` instead of the $().
# 3  
Old 08-27-2006
sorry no I meant I just have an arbitrary list of names and a while loop set on the $count of the lines in it...

only i can't figure in the loop how to make the line work

Code:
user=`cat file1.txt` # user to be $count line in that list?


user on each loop will be relevant to whichever iteration of the loop $count is already set to... Smilie

so... pseudocode

user becomes the $count down the list person for this loop
perform actions on this variable
# 4  
Old 08-27-2006
maybe this will help:

cat file1.txt | while read LINE; do
user=`echo $LINE`
done;

-chiru
# 5  
Old 08-27-2006
hi chiru_h thanks for the code but its still not exactly what I mean... your code wants to read input from the user
# 6  
Old 08-27-2006
in the end i winged it with...

Code:
echo `cat file.txt` | cut -d" " -f$count > temp.txt
user=`cat temp.txt`

thanks for the help in sorting this out... cheers
# 7  
Old 08-27-2006
Hi nortypig,
If I could suggest a couple of improvements in the code:
Code:
user=`cut -d" " -f$count file.txt`

This does exactly what you are doing, just more efficiently.
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 read one row at time using shell script?

Hello Team, I need information on how to read one row at time using shell script. For example i have below data. service-description servername warning critical mountpoint disk-usage-tmp generic-service test1 80 90 /tmp disk-usage-var ... (6 Replies)
Discussion started by: ghpradeep
6 Replies

2. IP Networking

Read() time out in socket programming

Hi, When can the read() system call gives timeout error when the same connection worked for writing data to the other end of the socket, while the next call with read() gives timeout error? Can anyone please explain when this kind of situation appears? Thanks, Sanzee (2 Replies)
Discussion started by: sanzee007
2 Replies

3. Shell Programming and Scripting

Read multiple lines at a time from file

Hello All, I have a file like below.... dn: cn=user1,ou=org,o=org cn=user1 uid=user1 cn=user2,ou=org,o=org cn=user2 uid=user2 cn=user3,ou=org,o=org cn=user3 cn=user33 uid=user3 cn=user4,ou=org,o=org cn=user4 uid=user4 (6 Replies)
Discussion started by: s_linux
6 Replies

4. Shell Programming and Scripting

Read two lines at time from a file

Hello community, what I need to do is read 2 rows at time from a file. I have this simple solution: File to read: LINE1 LINE2 LINE3 LINE4 LINE5 LINE6 LINE7 LINE8Read routine:#!/bin/ksh sed '1,3d' /out.txt | while read line; do read line2 echo $line $line2 doneResult:LINE1... (5 Replies)
Discussion started by: Lord Spectre
5 Replies

5. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

6. Shell Programming and Scripting

File read time

hi, how to check the file latest read time.. (2 Replies)
Discussion started by: rsivasan
2 Replies

7. Shell Programming and Scripting

Read two files at a time.

Hi friends, It's urgent. I am facing a problem. I want to read two files at a time, i mean line by line. My requirement is like , pls here find below while read line1fromfile1;do echo $line1fromfile1| .. echo $line1fromfile2---How i will do this done< file 1 can anyone... (5 Replies)
Discussion started by: pritish.sas
5 Replies

8. Shell Programming and Scripting

How to read/process a .gz file, one line at a time?

Hello I'm stuck trying to solve this KSH issue and I'm hoping someone out there can offer some suggestions. I want to read lots of large .gz files one line at a time in order to compare its Error entries with a list of known errors. I can't simply do "foreach ERROR do gzcat *.gz |grep... (2 Replies)
Discussion started by: dayscripter
2 Replies

9. Shell Programming and Scripting

How to read max of 10 file at a time?

Hi All, Please advise . Welcome more suggestions. For examples, I have 1000 file with prefix x??? In fact, I want to convert them to x???.txt with max 10 files at a time. As such, I will need to call another script to read from those 10 *txt files and sleep 5000 to convert the next 10 again.... (10 Replies)
Discussion started by: cedrichiu
10 Replies

10. Shell Programming and Scripting

Terminal Hungup at the time of read

Hi, There are two scripts. The second script is called from the first one. These will create two processes on unix. In the second script, there is a read statement in the while loop. Under unexpected conditions, at the time of reading response from the user, if the terminal hungup happens,... (1 Reply)
Discussion started by: pkusumam
1 Replies
Login or Register to Ask a Question