sed to change a configuration file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed to change a configuration file
# 1  
Old 07-22-2008
sed to change a configuration file

Hi

I want to create a configuration file from a template one.

The only thing to change for now is the port number that I need to take from another file that has this format:

serverSmilieort


So I need to take the 2nd field.

server is passed in the script argument.

how to do that? I think of sed to search the file and get the port then find the line

Listen 80

to

Listen <port>

and then saves a new config file.

thanks for your help.
# 2  
Old 07-22-2008
If you are sure it is always starting with the first character being the large 'L' and only 1 blank between "Listen" and "80" you can use this:
Code:
sed 's/^Listen 80/Listen \<Port\>/g' infile > httpd.conf.new

If you are unsure and want to get most possibilities taken into account (occurences of blanks and tabs etc.) you might use:
Code:
sed 's/^[<space>|<tab>]*Listen[<space>|<tab>]*80/Listen \<Port\>/g' infile > httpd.conf.new

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using sed to change file into an awk script

Hi I want to use sed to change a text files input into an awk script. For example if the input says " chord -- english " I want to change this using sed 's/pattern 1 /pattern 2 /'g filename but I don't understand how to use part of the pattern 1 to input that into pattern 2 . Like after... (10 Replies)
Discussion started by: enforcer
10 Replies

2. UNIX for Beginners Questions & Answers

File name change with sed

I have a bunch of text files like this: Sample_S1_L001_R1.txt Sample_S10_L001_R1.txt Sample_S11_L001_R1.txt I am using the following script to add a 0 to those files with a single digit after the S: ls *.txt | sed 's/\(.*_S\)\(_.*\)/mv & \10\2/' | sh And then the following script to... (4 Replies)
Discussion started by: Xterra
4 Replies

3. Shell Programming and Scripting

sed command not working for me to change text in a file

UNIX gurus I need your help with the following (The server is an AIX box). I have a text file with the following information: ******************************************************** SOME LINES case :WORD1 SOME LINES :WORD2 SOME LINES :WORD3 SOME LINES esac SOME LINES... (7 Replies)
Discussion started by: curiousmal
7 Replies

4. Shell Programming and Scripting

Trying to take file numbers from a file, pass them to sed to change strings in corresponding lines

I have a bunch of file numbers in the file 'test': I'm trying the above command to change all the instances of "H" to "Na+" in the file testsds.pdb at the line numbers indicated in the file 'test'. I've tried the following and various similar alternatives but nothing is working: cat test |... (3 Replies)
Discussion started by: crunchgargoyle
3 Replies

5. Shell Programming and Scripting

sed substitution or awk, need to direct change the file

I want change the file when the line contains $(AA) but NOT contains $(BB), then change $(AA) to $(AA) $(BB) eg: $(AA) something $(AA) $(BB) something (7 Replies)
Discussion started by: yanglei_fage
7 Replies

6. Shell Programming and Scripting

Creating a sed script to change ip addresses in a file

So I'm new to this sed command and I am trying to create a script that replaces ip addresses when I name a file but can't tweak it to work. Here is what it looks like: #!/bin/bash # file=$1 # sed -e 's/-CPUaddr 10.30.10.166/-CPUaddr 10.30.10.151/g' -i "$file" sed -e 's/-CPUaddr... (10 Replies)
Discussion started by: uradunce
10 Replies

7. UNIX for Dummies Questions & Answers

sed question - change 2d to last line in file

The file is repeating blocks of text separated by a blank line. Some of the lines are unique. e.g.: This is unique line This is line 2 This is line 3 This is line 4 This is unique line This is line 2 This is line 3 This is line 4 ... The goal is to change/replace line 4... (2 Replies)
Discussion started by: uiop44
2 Replies

8. Shell Programming and Scripting

how to change a number in a file with sed?

Hello, I have a file which contains some line as follows, 9.9 TEMP 9.9 MUCOEFF 0.0 EPSILON And I want to increase this MUCOEFF by 0.2 as 9.9 TEMP 10.1 MUCOEFF 0.0 ... (7 Replies)
Discussion started by: lorenzz
7 Replies

9. UNIX for Dummies Questions & Answers

I need to change printer configuration

We have several Printers that are pointing to a print server that is now defunct. I need to point these printers to the new print server. I am aware I need to change the configuration in /usr/spool/lp/admins/lp/printers/printername/configuration as well as in /etc/printers.conf. However my... (0 Replies)
Discussion started by: tugger
0 Replies

10. Shell Programming and Scripting

How to change this file with SED?

I have a file like below: I want to delete the rows which begining with "BC" "CD" and "TY" . then change every fields into one row like this at last delete the head words : USing awk to change it is not hard. I want to know how to do this work using SED ? Thank you! ... (4 Replies)
Discussion started by: bejgirl
4 Replies
Login or Register to Ask a Question