LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 03: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, 03:17 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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, 03:48 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,834

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

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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


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


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