Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-22-2015, 09:54 AM   #1
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

Old 02-22-2015, 11:01 AM   #2
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 231

Original Poster
Rep: Reputation: 5
Found it:

Dummy.txt =

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

result Dummy.txt =

a xxx
b xxx
c xxx


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 03:09 PM
Problem with sed lemon09 Programming 8 01-29-2010 08:07 AM
Sed problem Miro1 Programming 3 04-09-2005 09:02 AM
sed problem fossilet Linux - Software 4 12-26-2004 05:44 AM
sed problem Warmduvet Programming 2 09-15-2004 06:33 PM > Forums > Linux Forums > Linux - Newbie

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

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