Removing punctuation from txt file in Linux terminal using 'tr' and 'awk' commands
13,381
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.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on July 22, 2022Comments
-
Admin almost 2 years
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?
-
kvantour over 4 years
-
Andriy Makukha over 4 years@kvantour, yeah, I guess even with
cat
there is no guarantee thatcat
will finish reading beforeawk
wants to write to it. Thanks.