Sponsored Content
Top Forums Shell Programming and Scripting Pattern Matching and extracting the required fields in Perl Post 302623575 by durden_tyler on Friday 13th of April 2012 10:16:04 PM
Old 04-13-2012
Quote:
Originally Posted by filter
...
The file file_svn contains the following:
Code:
https://ims-svnus.com/dev/DB/trunk/feeds/templates/shell_script.txt -r860
https://ims-svnus.com/dev/DB/trunk/db/sec_db/stored_procedures/alter.sql -r990
https://ims-svnus.com/dev/DB/trunk/com/bin/aim/filter.java -r456
..so on

From the above,
1) Get the path after trunk and then create those directories under the /home/dev/filter/build/tmpl/ and /home/dev/filter/build/ovrd/ if they dont exists.
(excluding -r860 ..etc)

Example:
After Running the Perl Script for first line:
Code:
https://ims-svnus.com/dev/DB/trunk/feeds/templates/shell_script.txt -r860

The directories (/feeds/templates/) doesn't exists under /home/dev/filter/build/tmpl/ and /home/dev/filter/build/ovrd/ , then we have to create them.

Then the file should be saved as
/home/dev/filter/build/tmpl/feeds/templates/shell_script.txt
...
...
Maybe something like this?

Code:
$
$ cat file_svn
https://ims-svnus.com/dev/DB/trunk/feeds/templates/shell_script.txt -r860
https://ims-svnus.com/dev/DB/trunk/db/sec_db/stored_procedures/alter.sql -r990
https://ims-svnus.com/dev/DB/trunk/com/bin/aim/filter.java -r456
$
$
$ cat -n svn_extract.pl
     1  #!/usr/bin/perl -w
     2  use File::Path qw(make_path);
     3  use strict;
     4
     5  my @base_dirs = qw (/home/dev/filter/build/tmpl /home/dev/filter/build/ovrd);
     6  my $version_file = "file_svn";
     7
     8  open (FH, "<", $version_file) or die "Can't open $version_file: $!";
     9  while (<FH>) {
    10    m|^.*/trunk/(.*)/(.*?) -r\d+$|;
    11    my ($dir_path, $file_name) = ($1, $2);
    12    foreach my $base (@base_dirs) {
    13      my $dir_to_test  = "$base/$dir_path";
    14      my $file_to_test = "$base/$dir_path/$file_name";
    15      if (! -d $dir_to_test) {
    16        print "Creating dir and file: $file_to_test\n";
    17        make_path ($dir_to_test);
    18        open (F, '>', $file_to_test);
    19        close (F);
    20      } elsif (! -e $file_to_test) {
    21        print "Creating file: $file_to_test\n";
    22        open (F, '>', $file_to_test);
    23        close (F);
    24      } else {
    25        print "File: $file_to_test exists!\n";
    26      }
    27    }
    28  }
    29  close (FH) or die "Can't close $version_file: $!";
    30
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl pattern matching

hi i am trying to get digits inside brackes from file , whose structure is defined below CREATE TABLE TELM (SOC_NO CHAR (3) NOT NULL, TXN_AMOUNT NUMBER (17,3) SIGN_ON_TIME CHAR (8) TELLER_APP_LIMIT NUMBER (17,3) FIL01 ... (2 Replies)
Discussion started by: zedex
2 Replies

2. Shell Programming and Scripting

Pattern matching extracting urls from rss, shell scripts

Hi all, how could i do ? I have a Rss file, i want to extract only the Urls (many) matching http://www.xxx.com/trailers/ from that file and copy into another file. like " <pubDate>Wed, 29 Apr 2009 00:00:00 PST</pubDate> <content:encoded><!Apple - Movie Trailers - The Hangover"><img... (3 Replies)
Discussion started by: BremboloIV
3 Replies

3. Shell Programming and Scripting

Problem extracting just a part of a matching pattern

Hello everyone, this is my first post so please give me a hand. I apologize for my English, I'll try to be clear with my request. I need to write a script (Bash) which finds all the variables defined in the file .h of the folder and then writes the name of the files .c where these variables are... (1 Reply)
Discussion started by: paxilpaz
1 Replies

4. Shell Programming and Scripting

help extracting a matching pattern and next lines of match

Hi there, i'm having some problems just making an awk script (i've tried this way, but other way can be posible for sure), for the next file file.txt <register> <createProfile> <result>0</result> <description><!]></description> <msisdn>34661461174</msisdn> <inputOmvID>1</inputOmvID>... (6 Replies)
Discussion started by: vicious
6 Replies

5. Shell Programming and Scripting

Perl Pattern Matching

Hello experts, I have a file containing the following text(shortened here). File Begin ---------- < # Billboard.d3fc1302a677.imagePath=S:\\efcm_T4 < Billboard.d3fc1302a677.imagePath=S:\\efcm_T4 --- > # Billboard.d3fc1302a677.imagePath=S:\\efcm_Cassini >... (2 Replies)
Discussion started by: nmattam
2 Replies

6. Shell Programming and Scripting

Extracting the strings matching a pattern from a word

Hi All , I need to extract the strings that are matching with the pattern : CUST.<AnyStringOfAnyLength>.<AnyStringOfAnyLength> from a file and then write all these string into another file. e.g. If a file SOURCE contains following lines : IF(CUST.ABCD.EFGH==1) THEN CUST.ABCD.EFGH =... (7 Replies)
Discussion started by: swapnil.nawale
7 Replies

7. Shell Programming and Scripting

Extracting a string matching a pattern from a line

Hi All, I am pretty new to pattern matching and extraction using shell scripting. Could anyone please help me in extracting the word matching a pattern from a line in bash. Input Sample (can vary between any of the 3 samples below): 1) Adaptec SCSI RAID 5445 2) Adaptec SCSI 5445S RAID 3)... (8 Replies)
Discussion started by: jharish
8 Replies

8. Shell Programming and Scripting

Korn Shell for pattern matching and extracting

Guys, i'm new to shell scripting. Here's what i need. I need a shell script which would read a file containing only 1 line which never changes. File containts - SQL_Mgd_Svc_ELONMCL54496 |EMEA\brookkev, EMEA\fieldgra, EMEA\tidmamar, EMEA\attfiste, EMEA\baldogar, EMEA\clarkia2, EMEA\conwasha,... (9 Replies)
Discussion started by: butterfly20
9 Replies

9. UNIX for Dummies Questions & Answers

Extracting sub-string matching the pattern.

Hi, I have a string looks like the following: USERS 32767.9844 UNDOTBS1 32767.9844 SYSAUX 32767.9844 SYSTEM 32767.9844 EMS 8192 EMS 8192 EMS_INDEXES 4096 EMS_INDEXES 4096 8 rows selected. How do I extract a sub-string to get the expected output as following: EMS 8192 EMS_INDEXES 4096 ... (3 Replies)
Discussion started by: NetBear
3 Replies

10. Shell Programming and Scripting

sed pattern matching help required

Hi I am trying to pattern match with sed, if it finds a match I need it to insert characters at the 28th position, its working but its also adding an extra space and I don't know why, below is the code. sed 's/715023044/\n&/g' $asn | sed '/^71502304413-000/s/./B4/28' | sed -e :a -e... (4 Replies)
Discussion started by: firefox2k2
4 Replies
All times are GMT -4. The time now is 02:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy