开发者

Filter Records in a file based on first column value through AWK/SED

I have a file with the following records:

a,1

a,1,2

a,1,2,3

b,4

b,4,5

b,4,5,6

I want the output like this:

开发者_开发知识库a,1,2,3

b,4,5,6


It's really unclear what you are trying to do here. It's even less clear what you have tried so far (good StackOverflow questions usually involve some code)! You've read the FAQ, right?

If your input is in a file called input_file.csv, then the following awk program will give you the output you have said you want. Whether it will work for your real data is anyone's guess.

% awk -F',' '{
    lines[$1] = $0
}
END {
    for (line in lines) {
        print lines[line]
    }
}' input_file.csv

I offer no explanation as to what this simple script does, but a handy reference for awk.

Thanks for your appreciation!


As requested

awk '/......./' input
a,1,2,3
b,4,5,6
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜