ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have a vhost files that has like 10 or 15 domains configured, I want to split them per domain, is there a way to do it using a script, bash maybe?
Thats one of the most common uses of scripting: parsing text. Lately I have used Perl a lot for doing such tasks. Below is a program that opens a file, parses for a prompt, then prints some data from a fictional file.
Code:
#!/usr/bin/perl
my $file = "/location/to/file";
open(FILE,">$file");
while ($line = <FILE>) {
my $index = index($line,"PROMPT");
if ($index == 0) {
$index += 6;
my $data = substr($line,$index,$LENGTH_OF_DATA);
print "data from file: $data\n";
}
}
close(FILE);
Once you learn some simple syntax, you can whip up scripts pretty quick. The above introduces syntax you may have know clue about, but that is a small script that does something like what you need.
What does a vhosts file look like? You limit your potential assistance base to script writers that recognise what it is or can be bothered to go and find out on Google - "your friend".
I think this does what you need, given that the start and end patterns are as stated
<VirtualHost and </VirtualHost
I think this should do the job for you. You can easily format the numeric part of the redirect filename if you wish. This will put each record in a file of it's own. Here I have used DDD0 as the first file and DDD1 as the second etc.
PAix
PS sorry, but most all of my awk starts in a shell.
sorry for posting incomplete, i actually googled for the said script and found a couple, one in python and one in perl, but thank you for posting your input, turbo spool's input should help me in my quest for learning to script
You're welcome. I have had a Perl book before, but in my experience, for the size of the scripts written, its just easier to use the internet most of the time.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.