How to change column names in shell/bash?

2019-09-06 16:49发布

This question may be too simple for most of you, but I really don't want to do it manually. So, suppose I have a file in terminal such like this:

[dz2t@edison-s GWAS]$ head $PHENO
GWASID  CHILDID VSTNUM  GENDER  GA
1001    1001    11  Female  -9
1002    1002    11  Male    -9
1003    1003    11  male    -9
1004    1004    11  male    -9
1005    1005    11  Female  -9
1006    1006    11  Female  -9

How to change the names of first two columns from "GWASID" and "CHILDID" to "FID" and "IID". And the others remain unchanged?

标签: shell
1条回答
2楼-- · 2019-09-06 17:14

You can do this:

sed -e '1s/GWASID/FID/' -e '1s/CHILDID/IID/' YourFile

That says, on line 1 only, substitute GWASID with FID and CHILDID with IID. If you want it to overwrite the file, you need to add the -i flag after the word sed for in-place editing.

查看更多
登录 后发表回答