Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Fri Jun 18, 2021 10:40 am


Username:
Subject:
Message body:
Enter your message here, it may contain no more than 60000 characters. 

Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
Font size:
 
Font colour
Options:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Disable BBCode
Disable smilies
Do not automatically parse URLs
Confirmation code
Confirmation code:
In an effort to prevent automatic submissions, we require that you enter both of the words displayed into the text field underneath.
     

Topic review - How to replace \w SED multiple matches on the same line without piping
Author Message
Post subject: How to replace \w SED multiple matches on the same line without piping  |  Post Posted: Tue Oct 08, 2013 6:29 am
SED's replacing mechanism replaces only the first occurrence each line. To change this, use the "/g" flag.

Example when sed replaces first match only:
Code:
[root@rhel5 ~]# echo "test test asdf test" >test.html
[root@rhel5 ~]# echo "test test asdf test" >>test.html
[root@rhel5 ~]# sed -i 's/test/replacement/' test.html
[root@rhel5 ~]# cat test.html
replacement test asdf test
replacement test asdf test


Example when sed replaces all matches on each line:
Code:
[root@rhel5 ~]# echo "test test asdf test" >test.html
[root@rhel5 ~]# echo "test test asdf test" >>test.html
[root@rhel5 ~]# sed -i 's/test/replacement/g' test.html
[root@rhel5 ~]# cat test.html
replacement replacement asdf replacement
replacement replacement asdf replacement
Jump to:  
cronNews News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO