Sponsored Content
Full Discussion: replace line after a regex
Top Forums UNIX for Dummies Questions & Answers replace line after a regex Post 302310001 by the1armedcoder on Thursday 23rd of April 2009 11:59:03 AM
Old 04-23-2009
replace line after a regex

Hi,

I am trying to write a script which will modify a given account's settings by searching for a line in a file and then replacing the line after it. Here is a portion of my input file:

[0002]
type=friend
username=0002
secret=password
host=dynamic
dtmfmode=rfc2833
mailbox=0002
context=sip
insecure=very
canreinvite=no
nat=yes
realm=192.168.1.122
callerid="Phone2id" <0002>

[0003]
type=friend
username=0003
secret=password
host=dynamic
dtmfmode=rfc2833
mailbox=0003
context=sip
insecure=very
canreinvite=no
nat=yes
realm=192.168.1.122
callerid="Phone3id" <0003>

I want to replace "password". I want to match the line before "secret=password" to be sure it is changing the correct line as the username will be a unique identifier.

I have been trying to do this with sed but have not been able to make it work. Also, I am not limited to sed.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed: delete regex line and next line if blank

Hi, I want to write a sed script which from batiato: batiato/giubbe: pip_b.2.txt pip_b.3.txt pip_b.3mmm.txt bennato: bennato/peterpan: 123.txt consoli: pip_a.12.txt daniele: (2 Replies)
Discussion started by: one71
2 Replies

2. Shell Programming and Scripting

sed: how to replace regex with a ' (quote) mark

I've got a text file which has " marks where it there should be ' marks. I tried to do it with sed, but it won't allow me to escape the ' mark. Here's what I tried to do: sed 's/"/\\'/g' file.txt How can this be done? Thanks (3 Replies)
Discussion started by: CraigMoore
3 Replies

3. Emergency UNIX and Linux Support

search replace regex question

Hi, I need to run a search and replace on a large database, what I need to change is all instances of #### (eg. 1764 or 1964) to (####) (eg. (1764) or (1964)) But there might be other numbers in there such as (1764) and I do not need those changed to ((1764)) How can I... (7 Replies)
Discussion started by: lawstudent
7 Replies

4. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

5. UNIX for Dummies Questions & Answers

read regex from ID file, print regex and line below from source file

I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header. In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

6. Shell Programming and Scripting

Using regex's from file1, print line and line after matches in file2

Good day, I have a list of regular expressions in file1. For each match in file2, print the containing line and the line after. file1: file2: Output: I can match a regex and print the line and line after awk '{lines = $0} /Macrosiphum_rosae/ {print lines ; print lines } ' ... (1 Reply)
Discussion started by: pathunkathunk
1 Replies

7. Shell Programming and Scripting

Regex - search and replace

I have file which contains data in the following format all in a single line: BDW_PUBLN_ID DECIMAL(18:0) NOT NULL PRIMARY INDEX ARGO_ACCT_DEP_PI ( OFC_ID ,CSHBX_ID ,TRXN_SEQ_NUM ,PROCG_DT ) PARTITION BY RANGE_N(PROCG_DT BETWEEN DATE '2012-03-01' AND DATE '2014-12-31' EACH INTERVAL '1' MONTH );... (4 Replies)
Discussion started by: ysvsr1
4 Replies

8. Shell Programming and Scripting

Multi line regex for search and replace

I have text file like below: a.txt Server=abc Run=1 Time=120.123 Tables=10 Sessions=16 Time=380.123 Version=1.1 Jobs=5 Server=abc Run=2 Time=160.123 Tables=15 Sessions=16 Time=400.258 Version=2.0 (1 Reply)
Discussion started by: sol_nov
1 Replies

9. Shell Programming and Scripting

Replace HTML tags using sed regex

I need all the end tags of </font> to be replaced with new line yet enclosing tag to be retained </font>. Please help me in this regard. Input: <font>abc</font>def<font>ghi</font> Output: <font>abc</font> def <font>ghi</font> (3 Replies)
Discussion started by: Badhrish
3 Replies

10. UNIX for Beginners Questions & Answers

Regex Expression Replace

I have a XML file where there is a tag with like <wd:address_line_1>1234 Street</wd:address_line_1> I want to replace the values "1234 Street" with "Test Data". Different people have different address lines and i want to replace with a fixed value to mask the file. I was trying to use sed... (7 Replies)
Discussion started by: dr46014
7 Replies
newkey(1M)																newkey(1M)

NAME
newkey - create a new Diffie-Hellman key pair in the publickey database SYNOPSIS
[ [ DESCRIPTION
establishes new public keys for users and machines on the network. These keys are needed when using secure RPC or secure NFS service. prompts for a password for the given username or hostname and then creates a new public/secret Diffie-Hellman 192 bit key pair for the user or host. The secret key is encrypted with the given password. The key pair can be stored in the file, the NIS map, or entries in the LDAP directory. consults the entry in the name service switch configuration file (see nsswitch.conf(4)) to determine which naming service is used to store the secure RPC keys. If the entry specifies a unique name service, will add the key in the specified name service. However, if there are multiple name services listed, cannot decide which source to update and will display an error message. The user is required to specify the source explicitly with the option. In the case of NIS, should be run by the superuser on the master NIS server for that domain. In the case of LDAP, should be run by the superuser on a machine that has permission to update the entries in the LDAP directory. Options Create a new public/secret key pair for the privileged user at the given hostname. Prompts for a password for the given hostname. Create a new public/secret key pair for the given username. Prompts for a password for the given username. Update the database in the specified source: (for NIS), or (LDAP). Other sources may be available in the future. WARNINGS
HP-UX 11i Version 2 is the last HP-UX release on which NIS+ is supported. LDAP is the recommended replacement for NIS+. HP fully supports the industry standard naming services based on LDAP. AUTHOR
was developed by Sun Microsystems, Inc. SEE ALSO
chkey(1), keylogin(1), nsswitch.conf(4), publickey(4). newkey(1M)
All times are GMT -4. The time now is 08:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy