LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2014, 08:35 AM   #1
lwj94
LQ Newbie
 
Registered: Mar 2014
Posts: 1

Rep: Reputation: Disabled
removing punctuations from file input or standard input (UNIX)


I just began learning Unix and I'm trying to learn some stuff myself. How do I remove all punctuation from a file input or standard input? which means that the input must be called in a file and through a standard input method.

For example, if the input is:

"Hello", she said. "Nice to meet you!", he {thought aloud}.

Then the output should be:

Hello she said Nice to meet you he thought aloud
 
Old 03-24-2014, 08:43 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
tr used with [ : p u n c t : ] (spaces added to lazily avoid smileys), would work in this case. Or you could use sed or awk.

A quick google of your question will turn up plenty of actual examples. Choose your poison.

e.g http://an-compsci.blogspot.com/2009/...-in-linux.html

Last edited by szboardstretcher; 03-24-2014 at 08:44 AM.
 
1 members found this post helpful.
Old 03-24-2014, 09:02 AM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
With this InFile ...
Code:
"Hello", she said. "Nice to meet you!", he {thought aloud}.
... this tr ...
Code:
tr -d "[:punct:]" <$InFile >$OutFile
... produced this OutFile ...
Code:
Hello she said Nice to meet you he thought aloud
The tr means translate.
The -d means delete.
The [:punct:] identifies the character class of all punctuation marks.

There are other ways to accomplish the same purpose.
I like this one because (IMO) it is more readable than the others.

Daniel B. Martin

Last edited by danielbmartin; 03-24-2014 at 09:09 AM. Reason: Cosmetic improvement; no code change.
 
Old 03-24-2014, 09:07 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
[noparse][:punct:][/noparse] can be used to avoid [unct:]
sed 's/[[:punct:]]//g' works too...
 
  


Reply



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
[SOLVED] Using flac with standard input w1k0 Linux - Software 10 06-30-2011 07:33 PM
Standard input error business_kid Slackware 3 09-20-2010 03:16 AM
DDD and standard input Bassy Programming 0 09-02-2008 06:28 AM
Repeated "input: AT Translated Set 2 keyboard as /class/input/input" messages AcerKev Mandriva 2 09-16-2007 08:35 AM
parsing standard input with bash arosales Programming 3 07-16-2005 10:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:19 PM.

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
Open Source Consulting | Domain Registration