当前位置:  技术问答>linux和unix

100分求助Linux Sort对文件排序,很头痛,求帮助啊

    来源: 互联网  发布时间:2016-08-19

    本文导语:  原文件: *.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"...

原文件:
*.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任意一个构成

|

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"


|

$ 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","","仕入先","","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"

|
up熊猫党主席,想不到好的办法了。你的数据只要是每列用""引用的,列之间用逗号分隔的话,应该不会有问题

    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 高分求助高分求助高分求助高分求助高分求助高分求助
  • 怎样读取HZK24S前十区的内容啊???求助求助
  • 紧急求助!紧急求助!
  • 【求助】iplanet问题,求助高手解答!
  • 菜鸟求助,solaris下计算问题求助
  • 【求助】SOS紧急求助..............极为简单的问题...跪求....
  • 高分求助啊!求助SUSE 10.0 不能上网.
  • 急急急急急急急啊,紧急求助啊!!!!!满分求助啊!!!!!!
  • 求助:linux下 vim的配置(高分求助)
  • red hat怎么安装gcc啊!总是出错,求助求助啊!!!yum源怎么改啊!!
  • 求助~~求助 ~~linux文件读写问题
  • 求助:信号 --13 进程中断
  • 求助,安装了红帽子后进不了
  • 新装linux求助
  • linux的 iptables问题求助
  • (高分求助)请问,那里有软件开发的<设计文档>
  • 一个简单的问题,高分求助!!!
  • 紧急求助:Unix下给文件夹重命名用什么命令?谢谢!!!!
  • VJ的一个问题,高分求助,熟悉VJ得请进!
  • 高分求助


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3