LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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-13-2009, 02:02 AM   #1
crispyleif
Member
 
Registered: Mar 2005
Location: Norway, by the coast
Distribution: Debian and the likes
Posts: 190

Rep: Reputation: 31
sed s/something/multiple &/ don't get it..


An example :

"testfile" contains the line "this is a testfile."

#sed -n 's/test/&/p' testfile
#this is a testfile.
#
#sed -n 's/test/& &/p' testfile
#this is a test testfile.
#
#sed -n 's/test/& & &/p' testfile
#this is a test test testfile.

ALL in good order..or understanding at least..

Now :

#echo "test" | sed -n 's/test/&/p'
#test
#
#echo "test" | sed -n 's/test/& &/p'
#test st
#
#echo "test" | sed -n 's/test/& &/p'
#test st st

I don't get it anymore.. and I have tried. I just feel that this is something fundamentally easy, but I can't get my head around it.
 
Old 02-13-2009, 02:17 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Really strange, it works as expected for me:
Code:
$ echo "test" | sed -n 's/test/&/p'
test
$ echo "test" | sed -n 's/test/& &/p'
test test
$ echo "test" | sed -n 's/test/& & &/p'
test test test
 
Old 02-13-2009, 02:48 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Gnu ???
 
Old 02-13-2009, 03:24 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Non gnu (sed on Solaris 8 2/02 Sparc):
Code:
$ echo "test" | sed -n 's/test/&/p'
test
$ echo "test" | sed -n 's/test/& &/p'
test test
$ echo "test" | sed -n 's/test/& & &/p'
test test test
 
  


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
Changing multiple files with SED timmy01 Linux - Software 17 05-15-2007 08:10 AM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
sed - multiple matches on the same line mjoc27x Programming 6 04-17-2003 07:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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