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

FAQ
It is currently Wed Aug 23, 2017 9:00 am


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

Author Message
mandrei99
Post  Post subject: How to replace dot or any character with AWK  |  Posted: Tue Jan 28, 2014 6:35 am

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

Offline
 

How to replace dot or any character with AWK

Code:
echo 'This is a sentence. This is another sentence.' | awk  '{gsub(/\./,"",$0);print $0}' 
This is a sentence This is another sentence

Few notes:
- "gsub" is a string subroutine in awk. It requires at least three parameters: 1: the regular expression match, 2: the substitution and 3: the target string that is subject for substitution
- the substitution requires double quotes.

Below I'm replacing the "dot" character and also omitting the new line:
Code:
# echo 'This is a sentence. This is another sentence.' | awk  '{gsub(/\./,"",$0);printf $0}'
This is a sentence This is another sentence





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

Topics related to - "How to replace dot or any character with AWK"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. Remove the character before the last character with SED - shell scripting

mandrei99

0

1494

Wed Nov 04, 2009 10:49 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

59

Thu Jul 20, 2017 11:02 am

admin View the latest post

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

mandrei99

1

1817

Wed Jun 26, 2013 8:18 am

admin 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

4865

Thu Feb 25, 2010 8:08 am

debuser View the latest post

There are no new unread posts for this topic. How to replace \w SED multiple matches on the same line without piping

mandrei99

0

1056

Tue Oct 08, 2013 6:29 am

mandrei99 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

1130

Fri Apr 10, 2015 8:58 am

admin 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