我想sorting文件,并将输出存储到一个tmp文件。 这是我的文件看起来像:
this_is_my_file(没有扩展名)
Names Last_Name_Initial --- Alex G Nick D Jon J Cain V Anderson S Chris W
我知道sorting文件的命令是sort -n $PWD/this_is_my_file -o tmp但如何开始sorting之后--- ? 还有一个后续问题,如果您比较的文件没有扩展名,那么如何区分文本文件或xml文件?
我如何读取文件并将其redirect到一个variables?
如何在这里申请sed?
我怎样才能让一个Windowsbatch file改变一个环境variables?
如何在某些“if”语句中使用Windows版本标题以确定要检查哪些Windows更新?
按date字段在bash中sorting日志
在Python中扫描按键
如何使一个创build一个程序的40个同时实例的bash脚本?
windows xp命令行脚本(cmd.exe):set / p在if之间使用时不能正常工作。 为什么?
无法通过runas命令捕获输出
您可以使用:
head -n 2 file && tail -n +3 file | sort Names Last_Name_Initial --- Alex G Anderson S Cain V Chris W Jon J Nick D
它的工作如下:
使用head -n 2获得前两个标题行
使用tail -n +3获取从第3行开始的所有行
管道tail的输出与sort
使用&&将头部的输出与tail+sort合并
{ head -n 2 file && tail -n +3 file | sort; } > output
你可以使用分组结构:
{ # read and print the first 2 lines read line; echo "$line" read line; echo "$line" # and sort the rest sort } < this_is_my_file
另外,awk:
awk 'NR <= 2 {print; next} {print | "sort"}' this_is_my_file
一个后续的答案:一般来说,在unix-y系统中,名称文件不能保证文件的内容。 但是,您可以看到file命令对文件的说明:
$ cat > contains_xml <?xml version="1.0" encoding="ISO-8859-1" ?> <foo> <bar>baz</bar> </foo> $ file contains_xml contains_xml: XML document text $ cat > not_really.xml this is plain text $ file not_really.xml not_really.xml: ASCII text
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。