Sponsored Content
Top Forums Shell Programming and Scripting Extracting information from Config files /text processing Post 302278849 by oconmx on Wednesday 21st of January 2009 09:56:41 AM
Old 01-21-2009
Quote:
Originally Posted by summer_cherry
hope below perl can help a little.

Just put them in 8 different array.

Code:
#!/usr/bin/perl
$n=0;
open FH,"<a.txt";
while(<FH>){
	next if /(\{|#)/;
  $n++ if /\}/;
	my @tmp=split(/  */,$_,3);
	$tmp[2]=~s/;.*//;
	$user[$n]=$tmp[2] if $tmp[1] eq "use";
	$host_name[$n]=$tmp[2] if $tmp[1] eq "host_name";
	$alias[$n]=$tmp[2] if $tmp[1] eq "alias";
	$address[$n]=$tmp[2] if $tmp[1] eq "address";
	$check_command[$n]=$tmp[2] if $tmp[1] eq "check_command";
	$contact_groups[$n]=$tmp[2] if $tmp[1] eq "contact_groups";
	$notification_interval[$n]=$tmp[2] if $tmp[1] eq "notification_interval";
	$notification_period[$n]=$tmp[2] if $tmp[1] eq "notification_period";
	$notification_options[$n]=$tmp[2] if $tmp[1] eq "notification_options";
}

Great! it works like a charm.

Another quick question Summer_cherry, how can I do a multi-dimensional array for Contact Groups, Notifications periods and notification options? As you can see in the example, those have different options separated by comma. Is there an easy way to extract those ?

Again, thank you for your support, your script was very helpful and by far better than my existing solution Smilie

Regards,
Carlos
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting information from text fields.

Dear friends, I'm a novice Unix user and I'm trying to learn the ropes. I have a big task I have to accomplish and I'm convinced Unix can get the job done, I just haven't figured out how. I recently posted on the topic of cutting text between unique text patterns and somebody helped me a great... (24 Replies)
Discussion started by: spindoctor
24 Replies

2. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

3. Shell Programming and Scripting

processing file names using text files

Hi, I have to perform an iterative function on a set of 10 files. After the first round the output files are named differently than the input files. examples input file name = xxxx1.yyy output file name = xxxx1_0001.yyy I need to rename all of the output files to the original input... (5 Replies)
Discussion started by: ligander
5 Replies

4. UNIX for Advanced & Expert Users

Extracting the required text from log files

It would be highly appreciable if any one helps me in this. I am trying to get it done through Java but I love unix and believe it can be done within minutes with couple of lines. The input log file is a text file contains multiple entries seperated by a blank line. Each seperated entry... (7 Replies)
Discussion started by: hareeshram
7 Replies

5. Shell Programming and Scripting

Extracting anchor text and its URL from HTML files in BASH

Hi All, I have some HTML files and my requirement is to extract all the anchor text words from the HTML files along with their URLs and store the result in a separate text file separated by space. For example, <a href="/kid/stay_healthy/">Staying Healthy</a> which has /kid/stay_healthy/ as... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

6. Shell Programming and Scripting

matching and extracting info from text files

Hi all, I have two .txt file i.e. First text file: 2 4 1 4 Second text file 2 1.nii.gz 4 334.nii.gz 1 12.nii.gz 4 134.nii.gz If entry in 1st column of 1st text file matches the 1st column of 2nd text file, then copy the file (name of which is the second column) associated with... (4 Replies)
Discussion started by: vd24
4 Replies

7. Shell Programming and Scripting

Extracting/condensing text from multiple files to multiples files

Hi Everyone, I'm really new to all this so I'm really hoping someone can help. I have a directory with ~1000 lists from which I want to extract lines from and write to new files. For simplicity lets say they are shopping lists and I want to write out the lines corresponding to apples to a new... (2 Replies)
Discussion started by: born2phase
2 Replies

8. Programming

extracting text files

i m unable to extract data from one text files to different text files..i am able to concat two text files in d same file ---------- Post updated at 03:21 PM ---------- Previous update was at 03:16 PM ---------- i want a c program for it (2 Replies)
Discussion started by: asd123
2 Replies

9. Shell Programming and Scripting

extracting information from multiple files

Hello there, I am trying to extract (string) information ( a list words) from 4 files and then put the results into 1 file. Currently I am doing this using grep -f list.txt file1 . and repeat the process for the other 3 files. The reasons i am doing that (a) I do know how to code (b) each file... (4 Replies)
Discussion started by: houkto
4 Replies

10. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies
SAFE-RM(1)						User Contributed Perl Documentation						SAFE-RM(1)

NAME
safe-rm - wrapper around the rm command to prevent accidental deletions USAGE
safe-rm [ ... ] (same arguments as rm) DESCRIPTION
safe-rm prevents the accidental deletion of important files by replacing rm with a wrapper which checks the given arguments against a configurable blacklist of files and directories which should never be removed. Users who attempt to delete one of these protected files or directories will not be able to do so and will be shown a warning message instead. safe-rm is meant to replace the rm command so you can achieve this by putting a symbolic link with the name "rm" in a directory which sits at the front of your path. For example, given this path: PATH=/usr/local/bin:/bin:/usr/bin You could create the following symbolic link: ln -s /usr/local/bin/safe-rm /usr/local/bin/rm CONFIGURATION
Protected paths can be set both at the site and user levels. Both of these configuration files can contain a list of important files or directories (one per line): /etc/safe-rm.conf ~/.safe-rm If both of these are empty, a default list of important paths will be used. /usr/lib/* will protect all of the files inside the /usr/lib directory if they are referred to directly, but it will not protect your system against: rm -rf /usr/lib For a full protection, you should include both of these lines: /usr/lib /usr/lib/* EXIT STATUS
Same exit status as the real rm command. Note that if all file arguments are skipped by safe-rm then the exit status will be the same as the exit status of the real rm when no files arguments are present. BUGS AND LIMITATIONS
Note that if you put the following in your protected paths list: $ cat /etc/safe-rm.conf /usr/lib Then safe-rm will prevent you from deleting the directory: $ rm -rf /usr/lib Skipping /usr/lib /bin/rm: missing operand Try `/bin/rm --help' for more information. However it cannot protect you from the following: $ cd /usr/lib $ rm -f * AUTHOR
Francois Marier <francois@safe-rm.org.nz> SEE ALSO
rm(1) LICENSE AND COPYRIGHT
Copyright (C) 2008-2009 Francois Marier This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. perl v5.14.2 2012-05-28 SAFE-RM(1)
All times are GMT -4. The time now is 09:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy