List & While Loop


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List & While Loop
# 1  
Old 06-19-2008
List & While Loop

I want to store a set of string values in a 1-D array
and then iterate the list by using a loop.

Please help this dummySmilie

Last edited by ngagemaniac; 06-19-2008 at 07:41 AM.. Reason: Question not clear to others
# 2  
Old 06-19-2008
It's not really clear what you mean, but I guess something like

Code:
for f in john paul george ringo era; do
  grep "$f" stuff | sed etc
done

(We note that grep | sed is often a Useless Use of Grep but this is just an example.)

I sort of liked the O'Reilly awk book. Kernighan & Pike also has a few sections on awk, in a context where you see how they thought it fits in with the rest of Unix. There's loads of links over in the FAQ forums.

Last edited by era; 06-19-2008 at 04:35 AM.. Reason: Link to O'Reilly book, it's available free on-line
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Efficient way to loop through list

i have a variable that contains a list of files: varA="/var/tmp/hello_0_myapp /var/tmp/mello_1_myapp /var/tmp/jello_2_myapp /var/tmp/fello_3_myapp" And i'm calling this variable in several functions: col0 () { FILE=$(echo "${varA}" | egrep "_0_myapp" | sed "s~_0_myapp~~g")... (5 Replies)
Discussion started by: SkySmart
5 Replies

2. Shell Programming and Scripting

For Loop & SUM

pcmpath query device |awk 'BEGIN{print "DEVICE NAME\tSERIAL"} /DEVICE NAME/ {printf "%s\t", $5; getline; print substr($2, length($2)-3)}' This script returns output like below to pull out "DEVICE NAME SERIAL". ...... hdisk28 110B hdisk29 1112 hdisk30 1115 hdisk31 1116 hdisk32 1128... (2 Replies)
Discussion started by: Daniel Gate
2 Replies

3. Shell Programming and Scripting

Problem Using If & For loop in AWK Command

I am parsing file for the fields using awk command, first i check 26th field for two characters using substr function if it matches then using for loop on array i search 184th field for 4 chars if it matches then i print the required fields but on execution i get the error, please help...... (5 Replies)
Discussion started by: siramitsharma
5 Replies

4. Solaris

X2200 in reboot loop & mounting ZFS drive on other boxes

So I was patching a Solaris 10 U08 X86 X2200 box in preparation for an Oracle upgrade. Rebooted the box because the patches failed and the box will not boot successfully. I need to back up the zones on the 2 drives before going further. I pulled the drives and attempted to mount them on my Ubuntu... (0 Replies)
Discussion started by: LittleLebowski
0 Replies

5. Shell Programming and Scripting

awk & if loop

Dear All, I have a file with 1s and 0s with tab delimited file of approximately 535 lines and 1000 columns. I would like to print the lines, which are having 1s in it and i don't want to print the links with complete 0s. Is it possible to do the above one using awk with some looping. Need... (2 Replies)
Discussion started by: Fredrick
2 Replies

6. Shell Programming and Scripting

bash & Ksh loop problem

hi i was trying to optimize one script and i came across this problem .. i am putting some pseudo code here $ >cat a.sh ls | while read I do i=$(($i + 1)) done echo "total no of files : " $ >ksh a.sh total no of files : $ >bash a.sh total no of files : why is... (1 Reply)
Discussion started by: zedex
1 Replies

7. UNIX for Dummies Questions & Answers

loop & awk

I cut specific cell(row=2, column=1) in my excel file and created new file using following script. awk -F"," 'NR ==2 {print $1}' file1.csv > file1_new.csv awk -F"," 'NR ==2 {print $1}' file2.csv > file2_new.csv and so on.... The problem is that I have thousand files and I have to... (4 Replies)
Discussion started by: yonhk
4 Replies

8. Shell Programming and Scripting

Use file as list in for loop...

Can I use a file as the list in a for loop? I tried it like this: workstation=( $(cat /home/me/file) ) for ws in $workstation do command done The contents of file are like: abc def ghi It only read the initial line. Does each item have to be quoted? Do they have to all be... (11 Replies)
Discussion started by: earnstaf
11 Replies

9. UNIX for Dummies Questions & Answers

how to list a directory & file

Good day every body, Iv've been given a list of files and directory requested by the Auditor's. My problem is how do i list the file with the permission given and also save the file into text.file so that i can passed the result/oucome to them?? Thanks alot guys!! (2 Replies)
Discussion started by: gagasan_makmur
2 Replies

10. Shell Programming and Scripting

while loop from list

is it possible to run a while loop by comparing a variable with a list ? taglist="<html> </html> <head> </head> <body> </body> <p> </p> <ul> </ul> <li> </li> <em> </em> <title> </title>" read newtag while ] do echo "Entry is not in list, please try again' read newtag done... (6 Replies)
Discussion started by: forever_49ers
6 Replies
Login or Register to Ask a Question