Sponsored Content
Top Forums Shell Programming and Scripting Parse through a txt file PERL scripting Post 302972978 by Aia on Thursday 12th of May 2016 10:43:54 AM
Old 05-12-2016
A bit simpler?

Code:
#!/usr/bin/env perl
#
use strict;
use warnings;

my $env_file = '/apps/env_data.txt';
my $uenv = shift or die "Missing uenv parameter";

open my $fh, '<', $env_file or die "Unable to open $env_file: $!";

while(<$fh>) {
    if(/^$uenv\s/) {
        my ($env, $dir, $servers) = split;
        for my $server (split /,/, $servers) {
            system "ssh $server 'cat $dir/server.properties'";
        }
        last;
    }
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse the .txt file for folder name and FTP to the corrsponding folder.

Oracle procedure create files on UNIX folder on a regular basis. I need to FTP files onto windows server and place the files, based on their name, in the corresponding folders. File name is as follows: ccyymmddfoldernamefile.txt; Folder Name length could be of any size; however, the prefix and... (3 Replies)
Discussion started by: MeganP
3 Replies

2. Shell Programming and Scripting

CSV File parse help in Perl

Folks, I have a bit of an issue trying to obtain some data from a csv file using PERL. I can sort the file and remove any duplicates leaving only 4 or 5 rows containing data. My problem is that the data contained in the original file contains a lot more columns and when I try ro run this script... (13 Replies)
Discussion started by: lodey
13 Replies

3. UNIX for Dummies Questions & Answers

How to cut data block from .txt file in shell scripting

Hi All, Currently i have to write a script. For which i need to cut a block from .txt file. I know the specific word that starts the block and ends the block. Can we do it in shell scripting..? Please suggest.... (6 Replies)
Discussion started by: pank29
6 Replies

4. Shell Programming and Scripting

PERL:How to convert numeric values txt file to PACKED DECIMAL File?

Is there any way to convert numeric values txt file to PACKED DECIMAL File using PERL. Regards, Alok (1 Reply)
Discussion started by: aloktiwary
1 Replies

5. Shell Programming and Scripting

Parse file contents in perl...

Hi, I have the file like this: #Contents of file 1 are: Dec 10 12:33:44 User1 Interface: Probe Dec 10 12:33:47 uSER1 SOME DATA Dec 10 12:33:47 user1 Interface: MSGETYPE Dec 10 12:34:48 user1 ID: 10. Dec 10 12:33:55 user1 Interface: MSGTYPE Dec 10 12:33:55 user1 Id: 9 ... (1 Reply)
Discussion started by: vanitham
1 Replies

6. Shell Programming and Scripting

Perl: Parse Hex file into fields

Hi, I want to split/parse certain bits of the hex data into another field. Example: Input data is Word1: 4f72abfd Output: Parse bits (5 to 0) into field word1data1=0x00cd=205 decimal Parse bits (7 to 6) into field word1data2=0x000c=12 decimal etc. Word2: efff3d02 Parse bits (13 to... (1 Reply)
Discussion started by: morrbie
1 Replies

7. Shell Programming and Scripting

RegeX to parse data from a txt file

Hi all the experts out there, I am totally new to perl and I was given an assignment by using Perl to find the 2nd element of each line in each curly bracket which made up of 5 elements. Expected result should like this: Type: VCC Pin_name: AK32,AL32,AH21,..... Type: NC Pin_name:... (2 Replies)
Discussion started by: killbanne
2 Replies

8. Shell Programming and Scripting

Delete file2.txt from file1.txt using scripting

Hi, I`m a total newbie, well my requirement is that i have 2 files I want to identify which countries i do not currently have in db.. how can i use the grep or another command to find this file .. i want to match all-countries.txt with countries-in-db.txt so the output is equal to... (11 Replies)
Discussion started by: beanbaby
11 Replies

9. Shell Programming and Scripting

awk or perl to parse file

I have an input file attached that I am trying to parse in tab-delimanted format: The chromosomal variant column contains all the information: parse rules: 1. 4 zeros after the NC_ and the digits before the . 2. digits after the g. repeated twice separated by a tab 3. letter before the > 4.... (10 Replies)
Discussion started by: cmccabe
10 Replies

10. Linux

Scripting - parse file

Test jython (3 Replies)
Discussion started by: morpheus59
3 Replies
Regexp::RegGrp(3pm)					User Contributed Perl Documentation				       Regexp::RegGrp(3pm)

NAME
Regexp::RegGrp - Groups a regular expressions collection VERSION
Version 1.002 DESCRIPTION
Groups regular expressions to one regular expression SYNOPSIS
use Regexp::RegGrp; my $reggrp = Regexp::RegGrp->new( { reggrp => [ { regexp => '%name%', replacement => 'John Doe', modifier => $modifier }, { regexp => '%company%', replacement => 'ACME', modifier => $modifier } ], restore_pattern => $restore_pattern } ); $reggrp->exec( $scalar ); To return a scalar without changing the input simply use (e.g. example 2): my $ret = $reggrp->exec( $scalar ); The first argument must be a hashref. The keys are: reggrp (required) Arrayref of hashrefs. The keys of each hashref are: regexp (required) A regular expression replacement (optional) Scalar or sub. A replacement for the regular expression match. If not set, nothing will be replaced except "store" is set. In this case the match is replaced by something like sprintf("x01%dx01", $idx) where $idx is the index of the stored element in the store_data arrayref. If "store" is set the default is: sub { return sprintf( "x01%dx01", $_[0]->{store_index} ); } If a custom restore_pattern is passed to to constructor you MUST also define a replacement. Otherwise it is undefined. If you define a subroutine as replacement an hashref is passed to this subroutine. This hashref has four keys: match Scalar. The match of the regular expression. submatches Arrayref of submatches. store_index The next index. You need this if you want to create a placeholder and store the replacement in the $self->{store_data} arrayref. opts Hashref of custom options. modifier (optional) Scalar. The default is 'sm'. store (optional) Scalar or sub. If you define a subroutine an hashref is passed to this subroutine. This hashref has three keys: match Scalar. The match of the regular expression. submatches Arrayref of submatches. opts Hashref of custom options. A replacement for the regular expression match. It will not replace the match directly. The replacement will be stored in the $self->{store_data} arrayref. The placeholders in the text can easily be rereplaced with the restore_stored method later. restore_pattern (optional) Scalar or Regexp object. The default restore pattern is qr~x01(d+)x01~ This means, if you use the restore_stored method it is looking for x010x01, x011x01, ... and replaces the matches with $self->{store_data}->[0], $self->{store_data}->[1], ... EXAMPLES
Example 1 Common usage. #!/usr/bin/perl use strict; use warnings; use Regexp::RegGrp; my $reggrp = Regexp::RegGrp->new( { reggrp => [ { regexp => '%name%', replacement => 'John Doe' }, { regexp => '%company%', replacement => 'ACME' } ] } ); open( INFILE, 'unprocessed.txt' ); open( OUTFILE, '>processed.txt' ); my $txt = join( '', <INFILE> ); $reggrp->exec( $txt ); print OUTFILE $txt; close(INFILE); close(OUTFILE); Example 2 A scalar is requested by the context. The input will remain unchanged. #!/usr/bin/perl use strict; use warnings; use Regexp::RegGrp; my $reggrp = Regexp::RegGrp->new( { reggrp => [ { regexp => '%name%', replacement => 'John Doe' }, { regexp => '%company%', replacement => 'ACME' } ] } ); open( INFILE, 'unprocessed.txt' ); open( OUTFILE, '>processed.txt' ); my $unprocessed = join( '', <INFILE> ); my $processed = $reggrp->exec( $unprocessed ); print OUTFILE $processed; close(INFILE); close(OUTFILE); AUTHOR
Merten Falk, "<nevesenin at cpan.org>" BUGS
Please report any bugs or feature requests through the web interface at http://github.com/nevesenin/regexp-reggrp-perl/issues <http://github.com/nevesenin/regexp-reggrp-perl/issues>. SUPPORT
You can find documentation for this module with the perldoc command. perldoc Regexp::RegGrp COPYRIGHT &; LICENSE Copyright 2010, 2011 Merten Falk, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-02-18 Regexp::RegGrp(3pm)
All times are GMT -4. The time now is 01:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy