LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-29-2001, 06:55 PM   #1
bobthebat
Member
 
Registered: Apr 2001
Location: Portland, OR
Distribution: Slackware 8
Posts: 82

Rep: Reputation: 15
Question


I am trying to use sed to append the string value stored in a shell variable to a file. Here is what I am using:

sed <filename.txt -e a \ $SHELLVARIABLE

This gives me the error:

sed: -e expression #1, char 1: Extra characters after command

I have never used sed before, and so I tried to do it by only reading the manpage. Could someone please enlighten me on the correct syntax?
Thanks
 
Old 04-29-2001, 09:58 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Are you trying to replace the text in filename.txt with the shell variable or are you just trying to append the variable to the end of the file?

To replace:

cat filename.txt | sed "s/oldtext/$SHELL_VAR/"

To append
echo $SHELL_VAR >> filename.txt

It may be possibe to use sed, but it's not as easy.

Gary
 
Old 04-29-2001, 11:50 PM   #3
bobthebat
Member
 
Registered: Apr 2001
Location: Portland, OR
Distribution: Slackware 8
Posts: 82

Original Poster
Rep: Reputation: 15
Ok, here is what I want to do exactly, so that if there is a better way you can tell me:
I want to replace the text MONKEY in the file index.html with the output of the command
ifconfig ppp0
when I try to use the method you suggested, it says "unterminated 's' command".
 
Old 04-30-2001, 10:01 PM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Try this. It's not pretty, but it works. sed was choking on the newlines from the output of the ifconfig command. I used tr to translate the newlines into a new character, processed with sed and used tr to translate the character back.

Let me know if it works for you.

Gary

Code:
#!/bin/sh


cat index.html | sed "s/MONKEY/`ifconfig eth0 | tr '\n' '~'` /" \
               | tr '~' '\n' > index2.html
 
  


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
Ubuntu Fluxbox simple question, simple answer? generallimptoes Linux - Software 3 09-26-2005 02:03 PM
Simple question about sed or awk setianusa Programming 2 09-16-2005 03:57 PM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
Simple Text Reformat (sed and grep) mikefazz Programming 2 08-31-2004 07:38 PM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 09:03 PM

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

All times are GMT -5. The time now is 09:53 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