100分求助Linux Sort对文件排序,很头痛,求帮助啊
原文件:
*.dat
"AAA,BBB","902,686","","仕入先","","N","","PLA111901S","","2#2#0#3#","CC"
"AAA,BBB","902,686","","仕入先","","A","","PLA111901D","","2#2#0#3#","CC"
"AAABBB","902686","","仕入先","","N","","PLA111901K","","2#2#0#3#","CC"
"AAABBB","902686","","仕入先","","N","","PLA111901A","","2#2#0#3#","CC"
执行"sort -t, +7 -8 *.dat" 排序后:
"AAA,BBB","902,686","","仕入先","","A","","PLA111901D","","2#2#0#3#","CC"
"AAA,BBB","902,686","","仕入先","","N","","PLA111901S","","2#2#0#3#","CC"
"AAABBB","902686","","仕入先","","N","","PLA111901A","","2#2#0#3#","CC"
"AAABBB","902686","","仕入先","","N","","PLA111901K","","2#2#0#3#","CC"
预期想要的结果:
"AAABBB","902686","","仕入先","","N","","PLA111901A","","2#2#0#3#","CC"
"AAA,BBB","902,686","","仕入先","","A","","PLA111901D","","2#2#0#3#","CC"
"AAABBB","902686","","仕入先","","N","","PLA111901K","","2#2#0#3#","CC"
"AAA,BBB","902,686","","仕入先","","N","","PLA111901S","","2#2#0#3#","CC"
以第8列排序,逗号(,)是列的分割符,现在的问题是列的内容含有逗号(,)
* "PLA111901A"构成格式:
"PL": 固定
"A": 由A-Z任意一个构成
"11901":六位数字
"A": 由A-Z任意一个构成
------解决方案--------------------
C/C++ code
sort -t\" +15 -16 test.c
结果
"AAABBB","902686",""," 仕入先","","N","","PLA111901A","","2#2#0#3#","CC"
"AAA,BBB","902,686","","仕入先","","A","","PLA111901D","","2#2#0#3#","CC"
"AAABBB","902686",""," 仕入先","","N","","PLA111901K","","2#2#0#3#","CC"
"AA,BBB","902,686","","仕入先","","N","","PLA111901S","","2#2#0#3#","CC"
------解决方案--------------------
up熊猫党主席,想不到好的办法了。你的数据只要是每列用""引用的,列之间用逗号分隔的话,应该不会有问题
------解决方案--------------------
Perl code
$ cat aa | sed "s/\"\s*,\s*\"/\t/g" | sort -k 5 | sed "s/\t/\",\"/g"
"AAABBB","902686",""," 仕入先","","N","","PLA111901A","","2#2#0#3#","CC"
"AAA,BBB","902,686","",&q