LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2004, 08:49 AM   #1
chirophil91
LQ Newbie
 
Registered: Sep 2004
Distribution: RedHat 7.3
Posts: 4

Rep: Reputation: 0
sed and variable


Hi,
I've some problem with variables between my bash script and sed:

The script is invoked like:
script.sh my_file

Content of my_file:

blabla blabla blabla TopDesignName="old_pattern"

and i would like to have
blabla blabla blabla TopDesignName="new_pattern"

My bash script:

#!/bin/bash
NEW_PATTERN="new_pattern"
#I put the content of the last field ($NF) of the first record (NR<2) in #OLD_PATTERN variable (with " erased)
OLD_PATTERN=`awk -F "=" 'NR < 2 {print $NF} $1 | tr -d '\042'`
# and i want substitute the OLD_PATTERN by the NEW_PATTERN
cat $1 | sed "s/$OLD_PATTERN/NEW_PATTERN/" # don't work
#If I try
cat $1 | sed "s/old_pattern/NEW_PATTERN/" # work

So,I don't know how to pass the $OLD_PATTERN to sed ???

Thanks for your help
Philippe
 
Old 10-18-2004, 09:52 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Do you have to use a script and do you have to use sed?

awk -F= '{print$1"=new_pattern"}' file.txt > file1.txt
 
Old 10-19-2004, 03:23 AM   #3
chirophil91
LQ Newbie
 
Registered: Sep 2004
Distribution: RedHat 7.3
Posts: 4

Original Poster
Rep: Reputation: 0
Hi,

I think i have to use because the variable OLD_PATTERN is never the same,may be there is an easy solution
Thanks homey
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash, using variable in sed fur Programming 3 11-12-2005 07:41 AM
sed doesn't accept $variable in bash script chii-chan Programming 6 05-28-2005 07:07 AM
insert output of sed into a variable hwouters Linux - General 3 11-06-2004 07:54 PM
sed not working if value is passed thru a variable containg value suchi_s Programming 7 10-29-2004 07:41 AM
Expanding shell variable in sed goofyheadedpunk Programming 4 09-11-2004 05:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration