Skip to content

Instantly share code, notes, and snippets.

@caiqiqi
Last active March 26, 2018 17:21
Show Gist options
  • Save caiqiqi/dccb6e91e7125bfbb65ad9eb60b4df07 to your computer and use it in GitHub Desktop.
Save caiqiqi/dccb6e91e7125bfbb65ad9eb60b4df07 to your computer and use it in GitHub Desktop.
同学有个文件,需要转换一下格式,正好学习了一下awk的用法
# 开辟新的战场
mkdir wkl && cd wkl
# 将发送过来的压缩文件解压
unrar x *.rar
# 对ls中的所有文件(都是txt)的内容,取第10行开始到最后的内容,
# 由于她的文件内容有8列(但是8列中列与列之间有的是tab有的是空格分割的),再把前8列打印出来,重定向到新的文件
for i in `ls`;do awk 'NR>=10{print}' $i|awk '{print $1,$2,$3,$4,$5,$6,$7,$8}' > $i.modified.txt;done
# 打包/压缩
zip modified.zip *.txt
# 发送之后,清理现场
rm *.rar *.txt modified.zip
# 参考:https://coolshell.cn/articles/9070.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment