sed substitute situation


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed substitute situation
# 8  
Old 06-03-2005
Unfortunately yes.

Line from FILE:
SCCS=33.0

With this:
prev=$(awk -F"=" '{ print $2 }' $FILE)
new=$(echo "scale=1; $prev * 10" | bc )
sed "s/$prev/$new/g" $FILE

I get:
sed: command garbled: s/

Last edited by newbreed1; 06-03-2005 at 10:22 AM..
# 9  
Old 06-03-2005
1. what are the values for 'prev' and 'new'? Use 'echo' before sed-ding
2. again a couple of lines from the file $FILE - could be helpful
3. try: sed "s#$prev#$new#g" $FILE
# 10  
Old 06-03-2005
I receive the same results from:
sed "s#$prev#$sccs#g" $FILE

I am in bash. I am not sure how to tell what version I am using.
# 11  
Old 06-03-2005
Just to restate what vgersh99 said:

1. what are the values for 'prev' and 'new'? Use 'echo' before sed-ding

your value for prev is probably the problem. I imaging it is returning more than one result.
so this may help:

Code:
for value in ${prev} ; do
    sed "s/${value}/${new}/g" ${FILENAME} >> NEW_FILE
done

# 12  
Old 06-03-2005
Like this?
prev=$(awk -F"=" '{ print $2 }' $FILE)
new=$(echo "scale=1; $prev * 10" | bc )
echo $prev
echo $new
sed "s/$prev/$new/g" $FILE

I receive this:
33.0
330.0
sed: command garbled: s/

There is only one value in the file.
FILE has:
SCCS=33.0
# 13  
Old 06-03-2005
works fine for [Solaris 9]....
make sure your 'sed' [and the entire script] doesn't have any hidden/control chars [like ^M] - if you've been transfering files from one system to the other.
# 14  
Old 06-03-2005
Man... this stinks.
I am on SunOS 5.8
I can't figure out why this isn't working. When I do this from the command line:
prev=33.0; new=34.0; sed s/$prev/$new/g $FILE

it works fine. But within another script it fails.

It has got to be in the interpretation of the variables. When I just put in the values in the script explicitly like this:
sed s/33.0/34.0/g $FILE

It also works. So when $prev and $new are evaluated it is screwing up somewhere.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Substitute a character with sed

hi all, i'd like to modify a file with sed , i want to substuite a char "-" with "/" how can i do this? Thanks for all regards Francesco (16 Replies)
Discussion started by: Francesco_IT
16 Replies

2. Shell Programming and Scripting

[sed]: Substitute a string with a multiline value

Dear all, I try to replace a string of characters in a file (MyFile.txt) by a multiline value of the variable "Myvar": $ cat MyFile.txt DESCRIPTION '@TargetTable SCHEMA' ( @InputFlowDef ); $ The content of Myvar: $ echo "$Myvar" col1 , col2 , col3 $ (4 Replies)
Discussion started by: dae
4 Replies

3. Shell Programming and Scripting

sed substitute command -- need help

I am trying to do what I thought should be a simple substitution, but I can't get it to work. File: Desire output: I thought I'd start with a sed command to remove the part of the header line preceding the string "comp", then go on to remove the suffix of the target string (e.g. ":3-509(-)"),... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

4. Shell Programming and Scripting

using sed or gsub to substitute characters!

Is there a way to substitute the URL-encoding references of ( & and ` ) with their actual appearance? for example.... %26 is & say I want to convert every %26 in my file to &..... awk '{gsub(/%26/,"&");print}' Is there a way to do this? I also want to be able to convert ` too! (3 Replies)
Discussion started by: puttster
3 Replies

5. Shell Programming and Scripting

how to substitute filepaths with sed or awk?

I am having the following problem. I am having a lot of files (test_1_01.hea, test_1_02.hea, etc) with the content: project_directory /net/1/d_1/5/ tmp_directory /net/1/d_1/5/ material_directory /net/1/d_1/5/ And I have to substitute the filepaths with new counted ones where the... (3 Replies)
Discussion started by: ergy1983
3 Replies

6. Shell Programming and Scripting

Sed question to substitute data in \2

Hi All, Here is what I'm trying to do with sed: Input File: somechangeVariable1=Something I would like to change somechangeVariable2=Something else I would like to change ... Output File: somechangeVariable1=Something I would like to different somechangeVariable2=Something else I would... (6 Replies)
Discussion started by: Peace_Dude1
6 Replies

7. UNIX for Dummies Questions & Answers

Using sed to substitute between quotes.

I'm using sed to perform a simply search and replace. The typical data is: <fig><image href="Graphics/BAV.gif" align="left" placement="break" I need to replace the value in the first set of quotes, keeping the remainder of the line the same. Thus: <fig><image href="NEW_VALUE" align="left"... (3 Replies)
Discussion started by: Steve_altius
3 Replies

8. Shell Programming and Scripting

Using sed to substitute first occurrence

I am trying to get rid of some ending tags but I run into some problems. Ex. How are you?</EndTag><Begin>It is fine.</Begin><New> Just about I am trying to get rid of the ending tags, starts with </ and ending with >. (which is </EndTag> and </Begin>) I tried the following sed... (2 Replies)
Discussion started by: quixoticking11
2 Replies

9. Shell Programming and Scripting

Using SED to substitute between two patterns.

Hi All, I'm currently using SED to make various changes to some .xml files I'm working on, but I'm stuck on this particular problem. I want to remove '<placeholder>element-name</placeholder>' from the following: <heading>Element <placeholder>element-name</placeholder> not... (2 Replies)
Discussion started by: Steve_altius
2 Replies

10. Shell Programming and Scripting

sed situation

Hi, I'm looking for someone who can think in sed. Basically, I need the trailing characters on every line in a file to be deleted. These characters are all in capitals, and always follow a number, but they often vary in number For instance, on the line: 2006_10_9_p20_TALK I'd want to... (4 Replies)
Discussion started by: Laurel Maury
4 Replies
Login or Register to Ask a Question