Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing punctuation from txt file in Linux terminal using 'tr' and 'awk' commands

I'm currently taking a crash course in the basics of the Linux terminal and one of the tasks is to replace punctuation in a text file using 'awk' and 'tr' commands. I have tried searching around for solutions but nothing is working for me, any help?

like image 220
Harry Watson Avatar asked Mar 09 '18 17:03

Harry Watson


1 Answers

Using tr (as Glenn Jackman has already pointed out):

cat TEXTFILE | tr -d '[:punct:]' > OUTFILE

Using awk (tested with gawk and mawk):

cat TEXTFILE | awk '{ gsub(/[[:punct:]]/, "", $0) } 1;' > OUTFILE

You can also omit cat with AWK:

awk '{ gsub(/[[:punct:]]/, "", $0) } 1;' TEXTFILE > OUTFILE

Note: TEXTFILE and OUTFILE must be different.

like image 68
Andriy Makukha Avatar answered Oct 16 '22 21:10

Andriy Makukha