Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awk实现类似flatMap的效果 #53

Open
cjuexuan opened this issue Apr 28, 2018 · 0 comments
Open

awk实现类似flatMap的效果 #53

cjuexuan opened this issue Apr 28, 2018 · 0 comments

Comments

@cjuexuan
Copy link
Owner

awk行转列

今天一个同事在分析kafka的分区信息,他通过describe topic将所有的分区信息打到了一个csv文件,文件格式如下

//topic                               //partition ids
xm_passport.tb_thirdparty_user_adpter 11317,11417,11617

现在他想做的一件事情是做一个类似scala里的flatMap,

他期望的格式如下

xm_passport.tb_thirdparty_user_adpter 11317
xm_passport.tb_thirdparty_user_adpter 11417
xm_passport.tb_thirdparty_user_adpter 11617

于是找我帮忙,23333,估计看我长着一张运维脸:(

其实也很简单,awk简单弄下就行了

▶ cat test
xm_passport.tb_thirdparty_user_adpter 11317,11417,11617
xm_passport.tb_test 11317,11318,11417

~
▶ cat test| awk '{split($2,array,",");for (i in array){$2 = array[i];print $0}}'
xm_passport.tb_thirdparty_user_adpter 11417
xm_passport.tb_thirdparty_user_adpter 11617
xm_passport.tb_thirdparty_user_adpter 11317
xm_passport.tb_test 11318
xm_passport.tb_test 11417
xm_passport.tb_test 11317

~
▶
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant