sed question - replacing param values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed question - replacing param values
# 1  
Old 08-04-2008
sed question - replacing param values

Hello,

Do you have any idea why the below sed command is also replacing the value of "PARAMETER2" instead of just "PARAMETER" in file1 ?

Code:
% parameter=PARAMETER
% new_value=2
% cat file1
PARAMETER=1
PARAMETER2=1
% cat file1 | sed s/[^${PARAMETER}=]*$/${new_value}/1
PARAMETER=2
PARAMETER2=2

Thanks.
# 2  
Old 08-04-2008
Hammer & Screwdriver There is one extra * and $

> new_value=4
> cat file1 | sed s/[^{PARAMETER}=]/${new_value}/
PARAMETER=4
PARAMETER4=1
# 3  
Old 08-04-2008
Code:
$ parameter=PARAMETER
$ new_value=2
$ sed s/[^${parameter}=]/${new_value}/ file1
PARAMETER=2
PARAMETER2=1
$

# 4  
Old 08-05-2008
Thank you, It worked Smilie

btw it also works in ksh if I replace ${variable} with $variable
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replacing values inside a file.

Good day guys, I'm having trouble in creating a logic when it comes to replacing the values inside a file. I tried using sed command but it just doesn't work the way I want it to be. Here is what I'm trying to achieve. If my input file contains the values below. NAME++GUEST1 ++GUESS2++... (3 Replies)
Discussion started by: asdfghjkl
3 Replies

2. UNIX for Dummies Questions & Answers

Help in replacing column values

Hello All, I am having the file as below .I need to replace column 9-12 with some other values. In the below file I need to replace 1509 to 1508 and 1508 to 1507 .Can you please help me in how to do that Thanks, Arun ... (10 Replies)
Discussion started by: arunkumar_mca
10 Replies

3. Shell Programming and Scripting

Formatting and replacing according to block values

please consider the following file, there are repeated blocks of m values, and nested s values within. there are 2 columns (cols 3 and 4)associated with each m,s combination. All s1 rows must get a value of a(col 3 in output), all s2 values must get a value of b(col 3 in output). If s1 and s2 rows... (1 Reply)
Discussion started by: senhia83
1 Replies

4. Shell Programming and Scripting

Replacing values into a single column. sed/PERL

Hello everyone, i need to replace in the second column of my csv file, points by nothing and dash by comma like this: Input: 1 2 1;12.111.312-2;1.2;2;1-3 2 1 1;11.212.331-1;3.3;1;2-2 Output: 1 2 1;12111312;2;1.2;2;1-3 2 1 1;11212331;1;3.3;1;2-2 SED or PERL commands preferably. ... (7 Replies)
Discussion started by: satir
7 Replies

5. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

6. Shell Programming and Scripting

Replacing column values

hi all , ( perl) i am trying to replace jst one column in a file for eg month dayofweek dealar car-name jan thurs mercedes c300 feb wed lexus is300 all this data is in a master file and i want to replace jan with 1 feb... (5 Replies)
Discussion started by: technoman
5 Replies

7. Shell Programming and Scripting

Replacing string values from a File

I want to replace string values from a file to a file For eg : File1 has 30 lines of string with values, those specific values needs to be changed in file2 and remaining values in file2 should be as it is. For example: From file (File1) cluster.name=secondaryCluster To replace File... (9 Replies)
Discussion started by: sriram003
9 Replies

8. Shell Programming and Scripting

check for param values

I need to check for 4ht parameter values, if they are not in (17,18) in other words if they r not equal to 17 or 18 then exit. can u help pls (4 Replies)
Discussion started by: raopatwari
4 Replies

9. Shell Programming and Scripting

Replacing File values

Currently I am using the tr command in 3 scenarios for a ksh script. 1) Replacing any spaces in the file with a ~ tr ' ' '~' <$orignalFile> $newFile 2) After certain processing is done at the end of the scirpt i convert the Tilde back to spaces tr ' ' '~' <$newFile> $newFile2 3) Last... (4 Replies)
Discussion started by: hgjdv
4 Replies

10. Shell Programming and Scripting

replacing a line that may have different values on different servers

Replace disable_functions in php.ini with value of your choice which may be different on different servers ================================================ -bash-2.05b# grep disable_functions /usr/local/lib/php.ini disable_functions = 1 2 e weq t ret rye y etyhty rt et e ... (3 Replies)
Discussion started by: fed.linuxgossip
3 Replies
Login or Register to Ask a Question