LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-22-2015, 10:54 AM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 231

Rep: Reputation: 5
sed problem


I am trying to prepend and append some data to each line in a file. This works with hard coded literal data, but I can't get it to work a variable. I have tried thes instructions, but instead of prepending and appending what is contained in $mkred, the instruction is putting in '$mkred'.

sed -i 's/^/$mkred/' temp.txt # prepend to all

sed -i 's/^/\$mkred/' temp.txt # prepend to all

Thanks.
 
Old 02-22-2015, 12:01 PM   #2
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 231

Original Poster
Rep: Reputation: 5
Found it:

Dummy.txt =
a
b
c

var=" xxx" && sed -i "s/$/${var}/" dummy.txt

result Dummy.txt =

a xxx
b xxx
c xxx
 
  


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
[SOLVED] problem with sed sang_froid Programming 5 05-23-2011 04:09 PM
Problem with sed lemon09 Programming 8 01-29-2010 09:07 AM
Sed problem Miro1 Programming 3 04-09-2005 10:02 AM
sed problem fossilet Linux - Software 4 12-26-2004 06:44 AM
sed problem Warmduvet Programming 2 09-15-2004 07:33 PM


All times are GMT -5. The time now is 06:00 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration