gpt4 book ai didi

linux - 根据条件重新排列列

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:08:49 25 4
gpt4 key购买 nike

我有一个 *.csv 文件。值如下

"ASDP02","8801942183589"

"ASDP06","8801939151023"

"CSDP04","8801963981740"

"ASDP09","8801946305047"

"ASDP12","8801941195677"

"ASDP05","8801922826186"

"CSDP08","8801983008938"

"ASDP04","8801944346555"

"CSDP11","8801910831518"

或者有时值如下

"8801989353984","KSDP05" 

"8801957608165","ASDP11"

"8801991455848","CSDP10"

"8801981363116","CSDP07"

"8801921247870","KSDP07"

"8801965386240","CSDP06"

"8801956293036","KSDP10"

"8801984383904","KSDP11"

"8801944211742","ASDP09"

我只想将数值(例如 8801989353984)始终放在第一列。是否可以使用 BASH 脚本?

最佳答案

Sed 也是你的 friend

输入

cat 41189347
"ASDP02","8801942183589"
"ASDP06","8801939151023"
"CSDP04","8801963981740"
"ASDP09","8801946305047"
"ASDP12","8801941195677"
"ASDP05","8801922826186"
"CSDP08","8801983008938"
"ASDP04","8801944346555"
"CSDP11","8801910831518"

脚本

sed -E 's/^("[[:alpha:]]+.*"),("[[:digit:]]+")$/\2,\1/' 41189347

输出

"8801942183589","ASDP02"
"8801939151023","ASDP06"
"8801963981740","CSDP04"
"8801946305047","ASDP09"
"8801941195677","ASDP12"
"8801922826186","ASDP05"
"8801983008938","CSDP08"
"8801944346555","ASDP04"
"8801910831518","CSDP11"

关于linux - 根据条件重新排列列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41189347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com