LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 08-03-2006, 05:15 AM   #1
markhod
Member
 
Registered: Sep 2003
Posts: 103

Rep: Reputation: 15
sed question


Hi,

If I have a text file:

a
b
c

and I would like to change it to:

echo "a"
a
echo "b"
b
echo "c"
c

how can this be done with sed? I figured out how to add the extra line in, but not how to print the previous line inside the "" marks. Is this possible?

Or is there some other command similar to sed that will allow me to do this?

Thanks,

Mark
 
Old 08-03-2006, 05:53 AM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
do you mean something like the output of:
Code:
for a in $(<inputfile); do
    echo "echo \"$a\""
    echo "$a"
done > outputfile
 
Old 08-03-2006, 06:23 AM   #3
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Here's a sed command:
Code:
sed -r 's/(.*)/echo "\1"\n\1/'
 
Old 08-03-2006, 07:22 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by markhod
echo "a"
a
echo "b"
b
echo "c"
c
if this is really the output you need you can also try
Code:
sed s/.*/'echo "&"\n&'/
 
Old 08-03-2006, 07:24 AM   #5
markhod
Member
 
Registered: Sep 2003
Posts: 103

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by konsolebox
if this is really the output you need you can also try
Code:
sed s/.*/'echo "&"\n&'/
Thanks. That does the trick.

Cheers,

Mark
 
  


Reply



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
sed question? slack66 Linux - Newbie 7 07-26-2006 06:47 AM
sed question krock923 Programming 2 04-30-2006 09:36 PM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
SED question zivota Linux - General 8 07-26-2005 06:07 PM
sed question tifu Programming 5 03-18-2005 12:02 PM

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

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