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

FAQ
It is currently Fri Jan 19, 2018 8:04 am


Tips & Tricks, Questions regarding shell scripts, awk, perl, sed and much more.

Author Message
mandrei99
Post  Post subject: How to replace \w SED multiple matches on the same line without piping  |  Posted: Tue Oct 08, 2013 6:29 am

Joined: Tue Aug 04, 2009 9:16 am
Posts: 248

Offline
 

How to replace \w SED multiple matches on the same line without piping

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





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "How to replace \w SED multiple matches on the same line without piping"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. Echo new line in linux - supress new line or echo multiple new lines

mandrei99

0

3061

Wed Jan 14, 2015 5:26 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to replace new line in perl script

mandrei99

1

1974

Wed Jun 26, 2013 8:18 am

admin View the latest post

There are no new unread posts for this topic. grep match pattern: Binary file bincharacters.txt matches - How to make grep treat a file as text

mandrei99

0

847

Wed Dec 11, 2013 7:15 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to replace dot or any character with AWK

mandrei99

0

9010

Tue Jan 28, 2014 6:35 am

mandrei99 View the latest post

There are no new unread posts for this topic. AWK: How to replace a newline with actual \n

admin

0

246

Thu Jul 20, 2017 11:02 am

admin View the latest post

There are no new unread posts for this topic. SED how to remove multiple white spaces from a string

debuser

0

7611

Thu Feb 25, 2010 7:14 am

debuser View the latest post

There are no new unread posts for this topic. Unix shell - using TR to replace new lines with spaces

debuser

0

5269

Thu Feb 25, 2010 8:08 am

debuser View the latest post

There are no new unread posts for this topic. PERL: How to replace non-ascii characters/bytes in a file

admin

0

1404

Fri Apr 10, 2015 8:58 am

admin View the latest post

There are no new unread posts for this topic. SED uncomment line - How to uncomment a line or all lines with SED

mandrei99

0

3906

Wed Jan 14, 2015 5:08 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to convert a text into a list of words, one per line

LaR3

0

5276

Wed Aug 05, 2009 7:02 am

LaR3 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News 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