![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| while loop inside while loop | panknil | Shell Programming and Scripting | 0 | 01-07-2008 12:49 PM |
| For loop | xramm | HP-UX | 3 | 10-10-2007 02:20 PM |
| While Loop | hemangjani | Shell Programming and Scripting | 2 | 11-02-2006 11:01 AM |
| for loop | munnabhai1 | Shell Programming and Scripting | 3 | 04-06-2006 02:30 PM |
| how to get the similar function in while loop or for loop | trynew | Shell Programming and Scripting | 3 | 06-17-2002 11:09 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
for loop help
Hello-
I am new to the forum(forst post) and I am enthralled with the power of programming. I am writing a shell script to go into an apache config to add a ServerAlias mine to about 400 virtual servers. I am probably approaching this in the most difficult of ways since I am not familiar with the commands. BUT... The first question I have is how to use a file with a list in a for loop. So I have a file, named file.txt and it has 500 lines in it. I want the for loop to assign each line to the variable to process. I tried something like this: for i in 'cat file.txt' do this does not work since it wants to do something to "cat file.txt" How can I get it to process the list which is in the file.txt -Bob |
|
||||
|
That, my friends works very well. I hope you do mot mind me following up a more difficult question. This is where you may realize that my algorithm may not be up to the preschooler level.
If I knew regular expressions better, I would have probably attacked this directly with that. I am working within my framework of limited knowledge of the commands. I know that there are all kinds of resources on the web to learn this, but that is the problem. Anyway, dont laugh....too hard. I am using #!/bin/sh #make a list of the lines I need to use- edit and append on next line sed '/ServerName/!d; /domain.com/!d' httpd.conf > temp.txt #thankyou kindly for the help while read i do #I am trying to change add a ServerAlias to each of the sub-domains. Dont ask, #these customers are nuts. This is my attempt and does not work. convert=$(sed 's/ServerName /ServerAlias www./g') # would then try to use sed to append the line right under the original($i) I got. sed '/$i/ a\ $convert' done < temp.txt Maybe you could let me know of a better way to go about doing this. I am realizing this approach is flawed. -Bob |
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|