从第一栏中删除括号值,然后向第二栏中添加一些数据

时间:2018-12-06 11:09:25

标签: linux

我想从第一列中删除所有括号值,并在最后一列中添加一些字段

Sample Input
EXAMPLE(abc@gmail.com),60,6
EXAMPLE(bcd@gmail.com),30,6
EXAMPLE1(sample@gmail.com),60,3

Sample Output

EXAMPLE,60,6.ABC
EXAMPLE,30,6,ABC
EXAMPLE1,60,3,ABC

下面是我尝试过但没有运气的代码:

 for file_name in tmp/*.csv
    do
       sed -i 's/$/,"AB"/' "$file_name"| awk '{sub(/[(].*[)]/,"")}1' $file_name > tmp.csv && mv tmp.csv $file_name
    done

当我尝试单个文件时,它可以工作,但看起来不起作用:

sed -i 's/$/,"AB"/' abc.csv| awk '{sub(/[(].*[)]/,"")}1' abc.csv > tmp.csv

2 个答案:

答案 0 :(得分:0)

也许这样做:

awk '{sub(/[(].*[)]/,""); print $0",ABC"}' file | awk '{sub(/60,6,/,"60,6.")}1'

EXAMPLE,60,6.ABC
EXAMPLE,30,6,ABC
EXAMPLE1,60,3,ABC

答案 1 :(得分:0)

尝试一下

/tmp> cat jyoti.txt
EXAMPLE(abc@gmail.com),60,6
EXAMPLE(bcd@gmail.com),30,6
EXAMPLE1(sample@gmail.com),60,3
/tmp> perl -lne  's/\(.*\)//; print "$_,ABC" ' jyoti.txt
EXAMPLE,60,6,ABC
EXAMPLE,30,6,ABC
EXAMPLE1,60,3,ABC
/tmp>