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

FAQ
It is currently Tue Jun 06, 2023 7:33 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: 250

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

3891

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

2504

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

4929

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

8832

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

3447

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

3372

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:  
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