Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWK/SED. How to remove parentheses in simple text file

Tags:

sed

awk

I have a text file looking like this:

(-9.1744438E-02,7.6282293E-02) (-9.1744438E-02,7.6282293E-02)  ... and so on.

I would like to modify the file by removing all the parenthesis and a new line for each couple so that it look like this:

-9.1744438E-02,7.6282293E-02
-9.1744438E-02,7.6282293E-02
...

A simple way to do that?

Any help is appreciated,

Fred

like image 358
user1156777 Avatar asked Jan 18 '12 17:01

user1156777


2 Answers

I would use tr for this job:

cat in_file | tr -d '()' > out_file

With the -d switch it just deletes any characters in the given set.

To add new lines you could pipe it through two trs:

cat in_file | tr -d '(' | tr ')' '\n' > out_file
like image 196
Lee Netherton Avatar answered Sep 30 '22 04:09

Lee Netherton


As was said, almost:

sed 's/[()]//g' inputfile > outputfile

or in awk:

awk '{gsub(/[()]/,""); print;}' inputfile > outputfile
like image 41
ghoti Avatar answered Sep 30 '22 03:09

ghoti