Sponsored Content
Top Forums Shell Programming and Scripting create diffrent files based on other file and parameters list Post 302298590 by summer_cherry on Wednesday 18th of March 2009 03:51:48 AM
Old 03-18-2009
Code:
use strict;
my %hash=('A','audit','B','borrower','C','carriage','D','document');
sub l_sub{
	my ($id,$year,$name)=(@_);
	my $in_file =$hash{$id}."_paramter.prm";
	my $out_file=$hash{$id}."_paramter_".$name.".prm";
	open my $ifh,"<", $in_file  or die "Can not open file";
	open my $ofh,">>", $out_file or die "Can not open file";
	while(<$ifh>){
		if($.==2){
			$_=~s/\?/$name/;
		}
		if($.==3){
			$_=~s/\?\\\?/$year\\$name/;
		}
		print $ofh $_;
	}
}
open my $fh,"<","a.txt";
while(<$fh>){
	/(([A-Z])(\d{4}).*)/;
	l_sub($2,$3,$1);
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Create a shell script for write files with 2 parameters

Hello, I'm a newbie in shell script. So, i would like to create a shell script which take 2 IN parameters (PARAM1 and PARAM2). This script need to create 2 files as : I need to create this file /etc/apache2/sites-available/PARAM2 : <VirtualHost *:80> DocumentRoot "/home/PARAM1/www"... (0 Replies)
Discussion started by: chatlumo
0 Replies

2. UNIX for Advanced & Expert Users

Create a file based on multiple files

Hey everyone. I am trying to figure out a way to create a file that will be renamed based off of one of multiple files. For example, if I have 3 files (cat.ctl, dog.ctl, and bird.ctl) that gets placed on to an ftp site I want to create a single file called new.cat.ctl, new.dog.ctl, etc for each... (3 Replies)
Discussion started by: coach5779
3 Replies

3. Shell Programming and Scripting

Create files based on second column of a file

Hi All, I have a file which looks like this: 234422 1 .00222 323232 1 3232 32323 1 0.00222 1234 2 1211 2332 2 0.9 233 3 0.883 123 3 45 As you can see, the second column of the file is already sorted which I did using sort command. Now, I want to create files based on the second... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

4. UNIX for Dummies Questions & Answers

Need help how to create a file (xml) list all files from directory

I have more than 10K songs in two directories on a hard drive. I would like to create a file list all of files name then change to .xml extension to upload to iPhone so I have a Karaoke list on my iPhone. I need your help to create a file by using command in Linux. Files names: 0001 More... (4 Replies)
Discussion started by: ggcc
4 Replies

5. Shell Programming and Scripting

How to merge some files with diffrent sizes into one excel file using shell?

Hii I have these files , and I want to merge them in an excel file each file have two columns file1 title1 1 1 2 2 3 3 file2 title2 5 5 6 6 7 7 8 8 9 9 (10 Replies)
Discussion started by: maryre89
10 Replies

6. Shell Programming and Scripting

Create empty files from a list on file

Hello Guys. Please I would like to create empty files from a list In file1 will be the followin values, so i will like to create for each name a empty file. file1 2191off-r0.sps 2192off-r0.sps 2193off-r0.sps 2194off-r0.sps 2195off-r0.sps So I need to get 5 empty files. Thanks for... (7 Replies)
Discussion started by: jiam912
7 Replies

7. Shell Programming and Scripting

Comparing Select Columns from two CSV files in UNIX and create a third file based on comparision

Hi , I want to compare first 3 columns of File A and File B and create a new file File C which will have all rows from File B and will include rows that are present in File A and not in File B based on First 3 column comparison. Thanks in advance for your help. File A A,B,C,45,46... (2 Replies)
Discussion started by: ady_koolz
2 Replies

8. Shell Programming and Scripting

Create multiple files from single file based on row separator

Hello , Can anyone please help me to solve the below - Input.txt source table abc col1 char col2 number source table bcd col1 date col2 char output should be 2 files based on the row separator "source table" abc.txt col1 char (6 Replies)
Discussion started by: Pratik4891
6 Replies

9. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

10. UNIX for Beginners Questions & Answers

Create file based on data from two other files

I have looked through several threads regarding merging files with awk and attempted using join however have been unsuccessful likely as I do not fully understand awk. What I am attempting is to take a csv file which could be between 1 and 15,000 lines with 5 colums and another csv file that will... (4 Replies)
Discussion started by: cdubu2
4 Replies
PERLDBMFILTER(1)					 Perl Programmers Reference Guide					  PERLDBMFILTER(1)

NAME
perldbmfilter - Perl DBM Filters SYNOPSIS
$db = tie %hash, 'DBM', ... $old_filter = $db->filter_store_key ( sub { ... } ); $old_filter = $db->filter_store_value( sub { ... } ); $old_filter = $db->filter_fetch_key ( sub { ... } ); $old_filter = $db->filter_fetch_value( sub { ... } ); DESCRIPTION
The four "filter_*" methods shown above are available in all the DBM modules that ship with Perl, namely DB_File, GDBM_File, NDBM_File, ODBM_File and SDBM_File. Each of the methods work identically, and are used to install (or uninstall) a single DBM Filter. The only difference between them is the place that the filter is installed. To summarise: filter_store_key If a filter has been installed with this method, it will be invoked every time you write a key to a DBM database. filter_store_value If a filter has been installed with this method, it will be invoked every time you write a value to a DBM database. filter_fetch_key If a filter has been installed with this method, it will be invoked every time you read a key from a DBM database. filter_fetch_value If a filter has been installed with this method, it will be invoked every time you read a value from a DBM database. You can use any combination of the methods from none to all four. All filter methods return the existing filter, if present, or "undef" in not. To delete a filter pass "undef" to it. The Filter When each filter is called by Perl, a local copy of $_ will contain the key or value to be filtered. Filtering is achieved by modifying the contents of $_. The return code from the filter is ignored. An Example: the NULL termination problem. DBM Filters are useful for a class of problems where you always want to make the same transformation to all keys, all values or both. For example, consider the following scenario. You have a DBM database that you need to share with a third-party C application. The C application assumes that all keys and values are NULL terminated. Unfortunately when Perl writes to DBM databases it doesn't use NULL termination, so your Perl application will have to manage NULL termination itself. When you write to the database you will have to use something like this: $hash{"$key"} = "$value"; Similarly the NULL needs to be taken into account when you are considering the length of existing keys/values. It would be much better if you could ignore the NULL terminations issue in the main application code and have a mechanism that automatically added the terminating NULL to all keys and values whenever you write to the database and have them removed when you read from the database. As I'm sure you have already guessed, this is a problem that DBM Filters can fix very easily. use strict; use warnings; use SDBM_File; use Fcntl; my %hash; my $filename = "filt"; unlink $filename; my $db = tie(%hash, 'SDBM_File', $filename, O_RDWR|O_CREAT, 0640) or die "Cannot open $filename: $! "; # Install DBM Filters $db->filter_fetch_key ( sub { s/$// } ); $db->filter_store_key ( sub { $_ .= "" } ); $db->filter_fetch_value( sub { no warnings 'uninitialized'; s/$// } ); $db->filter_store_value( sub { $_ .= "" } ); $hash{"abc"} = "def"; my $a = $hash{"ABC"}; # ... undef $db; untie %hash; The code above uses SDBM_File, but it will work with any of the DBM modules. Hopefully the contents of each of the filters should be self-explanatory. Both "fetch" filters remove the terminating NULL, and both "store" filters add a terminating NULL. Another Example: Key is a C int. Here is another real-life example. By default, whenever Perl writes to a DBM database it always writes the key and value as strings. So when you use this: $hash{12345} = "something"; the key 12345 will get stored in the DBM database as the 5 byte string "12345". If you actually want the key to be stored in the DBM database as a C int, you will have to use "pack" when writing, and "unpack" when reading. Here is a DBM Filter that does it: use strict; use warnings; use DB_File; my %hash; my $filename = "filt"; unlink $filename; my $db = tie %hash, 'DB_File', $filename, O_CREAT|O_RDWR, 0666, $DB_HASH or die "Cannot open $filename: $! "; $db->filter_fetch_key ( sub { $_ = unpack("i", $_) } ); $db->filter_store_key ( sub { $_ = pack ("i", $_) } ); $hash{123} = "def"; # ... undef $db; untie %hash; The code above uses DB_File, but again it will work with any of the DBM modules. This time only two filters have been used; we only need to manipulate the contents of the key, so it wasn't necessary to install any value filters. SEE ALSO
DB_File, GDBM_File, NDBM_File, ODBM_File and SDBM_File. AUTHOR
Paul Marquess perl v5.12.5 2012-11-03 PERLDBMFILTER(1)
All times are GMT -4. The time now is 11:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy