![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell Script Create List of Deleted Files | mirfan | Shell Programming and Scripting | 8 | 01-22-2009 08:22 AM |
| how to List out the Files based on the file Size...? | psiva_arul | Shell Programming and Scripting | 6 | 04-08-2008 10:06 PM |
| Create a list of files that were modified after a given date. | rkka | UNIX for Dummies Questions & Answers | 4 | 01-22-2008 05:12 AM |
| copying files from one location to another based on a list | rebornhonest | UNIX for Dummies Questions & Answers | 4 | 11-30-2007 03:32 PM |
| how to create new dir fro a file list | banjo | Shell Programming and Scripting | 8 | 09-14-2006 11:21 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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
|
|
||||
|
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! |
|
||||
|
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? |
![]() |
| Bookmarks |
| Tags |
| create different files based |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|