The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-13-2009
raghav525 raghav525 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
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 (permalink)  
Old 03-16-2009
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
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 (permalink)  
Old 03-16-2009
raghav525 raghav525 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
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 (permalink)  
Old 03-17-2009
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
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 (permalink)  
Old 03-17-2009
raghav525 raghav525 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
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 too? Thanks
  #6 (permalink)  
Old 03-17-2009
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
Yes, use dos2unix or dos2ux (based on your OS) on the mainfile.txt to get rid of the ctl characters at the end.
  #7 (permalink)  
Old 03-17-2009
Goldorakk's Avatar
Goldorakk Goldorakk is offline
Registered User
  
 

Join Date: Feb 2009
Location: France
Posts: 43
Use the GNU utilities for Win32
You'll find head.exe, ls.exe, ...
Closed Thread

Bookmarks

Tags
create different files based

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0