Sponsored Content
Top Forums Shell Programming and Scripting Using SED to generate new file from template Post 302338547 by ppucci on Tuesday 28th of July 2009 08:33:18 AM
Old 07-28-2009
Quote:
Originally Posted by edidataguy
I would sugest changing all the lines as follows:
Code:
; "s|CUR_MGMT_INT|$CUR_MGMT_INT|"\
; "s|CUR_MGMT_INT|$CUR_MGMT_INT|"\

Hey, thank you for that... I did not see it was duplicated... it did not keep the script from running, it just addded unecessary steps to it.. Smilie

Quote:
Originally Posted by edidataguy
Why do you need the "-e" and the "/g" options.
Well, I am new to sed, but from what I read -e is to inform that the following is still part of the script (instead of going sed "1..."; sed "2..."; sed "3..." you use sed -e "1..." -e "2..." -e "2..."). As for g, it is to replace all occurrences of searched text, isn't it? Well they may appear more than once on the template files...

Quote:
Originally Posted by edidataguy
Regarding the " " issue post the input and the output.
Here is one record from the source file (all sensitive data was replaced, line break for readability):

Code:
persio@dynaserver:~/CUS$ more test
,"United States",226,,10.10.10.@,,10.10.10.@,255.255.255.128,Springfield,coresw1.cutomer.com,
WS-C3750G-12S-E,SERIALNO,SWIA8,12.2(35)SE5,10.10.10.@,255.255.255.192,Vlan997,"Switch Co
re L3",1,10.10.10.10,,,,2,ospf 12345,area 0,hsrp,,,,SWL3-2,#N/A,226-10_10_10_@-SWL3-2.txt
persio@dynaserver:~/CUS$

This record will use the following template according to its UnID (in red):

Code:
persio@dynaserver:~/CUS$ more SWL3-2
config t
!
vlan 996
desc Management VLAN
!
interface vlan 996
ip address IP_MGMT NEW_MASK
!
router ROUTING_PROCESS
network IP_MGMT 0.0.0.0 OSPF_AREA
!
! Trunk Configuration
TRUNK_DATA
! End trunk configuration
end
persio@dynaserver:~/CUS$

And when I run the script, this is the output file:

Code:
persio@dynaserver:~/CUS$ ./generate_config.sh test
reading test
persio@dynaserver:~/CUS$ more CONFIGS/SWL3-2/226-10_10_10_@-SWL3-2.txt
config t
!
vlan 996
 desc Management VLAN
!
interface vlan 996
 ip address 10.10.10.@ 255.255.255.128
!
router "ospf 10226"ESS
 network 10.10.10.@ 0.0.0.0 "area 0"
!
! Trunk Configuration
interface FastEthernet0/0
 switchport trunk allowed vlan add 996
! End trunk configuration
end
persio@dynaserver:~/CUS$

Details in blue are placeholder (on template) and replaced data (on output). Deatils in orange are unwanted characters that sed is including to the output file. I wanted to understand (1) why is it happening and (2) what can I do to prevent that?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

configuration and template file

Hi, I have a configuration file(which has values) and a template file(where the values are dummied) Configuration file (a.txt) -------------------- var1=1521 var2=172.10.10.10 var3=emp . . . var15=hhhhhhh Template file (b.txt) -------------------- The host name is $var2. The... (5 Replies)
Discussion started by: ammu
5 Replies

2. Shell Programming and Scripting

sed script to generate hyperlinks refuses to work

Hi All, I'm new to the forum and not a programmer, but I'm writing a bash script to preprocess definitions of technical terms by inserting hyperlinks pointing to other pages in the glossary before the pages are posted to our server, using a standard naming convention for the pages. The... (3 Replies)
Discussion started by: markfgilliland
3 Replies

3. Shell Programming and Scripting

Reading columns, making a new file using another as template

Hi fellas, I have two files such as: File 1 interacao,AspAsp,AspCys,CysAsp,CysCys,classe File 2 interacao,AspAsp,CysAsp,AspCys,CysCys,classe beta_alfa, DA, CA, DD, CD,ppi Thus, I want to make a File 3 using the File 1 as model: e.g. File 3... (2 Replies)
Discussion started by: valente
2 Replies

4. Shell Programming and Scripting

filling in strings in a template file using awk

Hi all, I have a template form to fill in for quite a number of files and I want to automate the filling-in process. the concept seemed to be simple but i cant get it work. the template form is a text file containing the information below: File Name: Date Created: Contents: I need to... (4 Replies)
Discussion started by: ida1215
4 Replies

5. Shell Programming and Scripting

Creating a larger .xml file from a template(sample file)

Dear All, I have a template xml file like below. ....Some---Header....... <SignalPreference> ... <SignalName>STRING</SignalName> ... </SignalPreference> ......Some formatting text....... <SignalPreference> ......... ... (3 Replies)
Discussion started by: ks_reddy
3 Replies

6. UNIX for Dummies Questions & Answers

XML File Generation - Template Help

Hi, I have hit a bit of a brick wall.:confused: need the following code edited: echo "<?xml version=\"1.0\"?><dailyBalance_ROWSET>" > ${DataDir}/${extract_script}${ApplicationDate}.${Suffix} RunSQL ${extract_script} ${ActionFlag} echo "</dailyBalance_ROWSET>" >>... (2 Replies)
Discussion started by: Xergxes7
2 Replies

7. Linux

Search a template file and replace with input

Hi I have a CommonTemplateStop.template file . Inside the file i need to replace the variables DepName and CompInsName with the values(Trade and TradeIns) specified in the script. I have written the below .sh script in linux server which will read the .template file and has to replace the 2... (8 Replies)
Discussion started by: samrat dutta
8 Replies

8. Shell Programming and Scripting

Inputing info from a CSV file and filling a template file

Hi, I have a .csv file that contains a variety of fields for 60 clients: USERNAME, PASSWORD, and COMMENTS. I have a template file which contains a great deal of data for each client and has the fields USERNAME, PASSWORD, and COMMENTS that has to be filled with the values of USERNAME,... (1 Reply)
Discussion started by: mojoman
1 Replies

9. Shell Programming and Scripting

Merge strings from a file into a template

I am preparing a morphological grammar of Marathi to be placed in open-source. I have two files. The first file called Adverbs contains a whole list of words, one word per line A sample is given below: आधी इतक इतपत उलट एवढ ऐवजी कड कडनं कडल कडील कडून कडे करता करिता खाल (2 Replies)
Discussion started by: gimley
2 Replies

10. UNIX for Beginners Questions & Answers

Generate files and use csv data to replace multiple variables in a template

I have a source csv file consists of first field as variable name, and the rest are site-specific information (converted from excel file, where site -specific values in columns). I am trying to create a file for every site using a template and replace the multiple variables with values from the... (3 Replies)
Discussion started by: apalex
3 Replies
All times are GMT -4. The time now is 05:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy