create diffrent files based on other file and parameters list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting create diffrent files based on other file and parameters list
# 1  
Old 03-13-2009
Question create diffrent files based on other file and parameters list

I would like ot create shell script/ bash to create diffrent files based on a file and parameters list.

Here is the detail example: I have a textfile and four static parameter files (having ‘?'). mainfile.txt has below records (this count may be more than 50)
A200001
A200101
B200001
B200002
C200001
D200101
D200102
D200201

And 4 static parameter files corresponding to records in mainfile.txt, started with A,B,C,D
1.audit_paramter.prm
[PQRS.temp_info]
$$Source_file_audit=?
$$Source_file_audit_dir = \\dal1mspcx55\cogent$\productionqc\?\?

2.borrower_paramter.prm
[PQRS.temp_info]
$$Source_file_borrower =?
$$Source_file_borrower_dir = \\dal1mspcx55\cogent$\productionqc\?\?

3.carriage_paramter.prm
[PQRS.temp_info]
$$Source_file_carriage =?
$$Source_file_carriage_dir = \\dal1mspcx55\cogent$\productionqc\?\?

4.document_paramter.prm
[PQRS.temp_info]
$$Source_file_document =?
$$Source_file_document_dir = \\dal1mspcx55\cogent$\productionqc\?\?


Now I would like to create different parameter files based on the records from mainfile.txt and using static parameter files

If records starts with A, it should create audit_paramter_*.prm such as
audit_paramter_A200001.prm
[PQRS.temp_info]
$$Source_file_audit=A200001
$$Source_file_audit_dir = \\dal1mspcx55\cogent$\productionqc\2000\A200001

audit_paramter_A200101.prm
[PQRS.temp_info]
$$Source_file_audit=A200101
$$Source_file_audit_dir = \\dal1mspcx55\cogent$\productionqc\2001\A200101

If records starts with b, it should create borrower_paramter_*.prm and so on.. like 8 different parameter files??? Would this possible do with sed / scripting??? Can someone please assist?

I can replace ‘?' with other symbols to differentiate two different values

Thanks in advance
# 2  
Old 03-16-2009
Solution in script

Code:
while read record
do
 year=`expr substr ${record} 2 4`
 case $record in
  A*)
      PARM_FILE="audit_parameter_${record}.prm"
      echo "[PQRS.temp_info]" > $PARM_FILE
      echo "\$\$Source_file_audit=${record}" >> $PARM_FILE
      echo "\$\$Source_file_audit_dir = \\\\dal1mspcx55\\\cogent\$\\productionqc\\${year}\\${record}" >> $PARM_FILE
      ;;
  B*) 
      PARM_FILE="borrower_parameter_${record}.prm"
      echo "[PQRS.temp_info]" > $PARM_FILE
      echo "\$\$Source_file_borrower=${record}" >> $PARM_FILE
      echo "\$\$Source_file_borrower_dir = \\\\dal1mspcx55\\\cogent\$\\productionqc\\${year}\\${record}" >> $PARM_FILE
      ;;
  C*)
      PARM_FILE="carriage_parameter_${record}.prm"
      echo "[PQRS.temp_info]" > $PARM_FILE
      echo "\$\$Source_file_carriage=${record}" >> $PARM_FILE
      echo "\$\$Source_file_carriage_dir = \\\\dal1mspcx55\\\cogent\$\\productionqc\\${year}\\${record}" >> $PARM_FILE
      ;;
  D*)
      PARM_FILE="document_parameter_${record}.prm"
      echo "[PQRS.temp_info]" > $PARM_FILE
      echo "\$\$Source_file_document=${record}" >> $PARM_FILE
      echo "\$\$Source_file_document_dir = \\\\dal1mspcx55\\\cogent\$\\productionqc\\${year}\\${record}" >> $PARM_FILE
      ;;
 esac 
done<mainfile.txt

# 3  
Old 03-16-2009
Thanks for the solution

Hi Krishmath...

Thanks for the soultion. Result as expected except with two things...
1. All parameter are creating with space (i can say "with new line") after the $record value such as borrower_parameter_B200103
.prm

2. It is not reading the last record of the file and not creating the parameter for that.

Content of the newly created files are really good. Can you please provide the solution for these two...

Thanks for your help!
# 4  
Old 03-17-2009
I tested the code and I'm getting the correct parameter file name, such as audit_parameter_A200101.prm

Are you transferring the mainfile.txt from Windows to Unix? What do you see when you open the file in vi? Are there any special characters at the end?
# 5  
Old 03-17-2009
Question????

Yes... This mainfile.txt is getting copied from windows server and i can see ctl chars when i open it on Unix. Any solution for this tooSmilie? Thanks
# 6  
Old 03-17-2009
Yes, use dos2unix or dos2ux (based on your OS) on the mainfile.txt to get rid of the ctl characters at the end.
# 7  
Old 03-17-2009
Solution

Thanks much! It worked... I used the command
cat /u01/opt/incoming/mainfile.txt | tr -d '\015' > /u01/opt/incoming/mainfile.txt

Prgm is working as expected. Thanks lot... Smilie

Last Question.. Do you have any idea on DOS commands?
I need a similar dos command for this? to select first file of similar pattern of files in one directory...
ls /u01/opt/incoming/abc_*.txt | head -1


Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question