如何在shell脚本中读取CSV头

时间:2017-04-26 10:36:04

标签: shell unix

我是shell脚本的新手。我需要读取csv页眉和页脚的shell脚本。 感谢

1 个答案:

答案 0 :(得分:0)

快速,2文本文件操作的基本工具:sed和awk 你也可以使用grep很少或没有修改但只是捕捉信息

使用sed:

# print 1st and last line only (-n mean no print by default, p mean print)
sed -n '1p;$p' YourFile
#or
# print if 1st, print if last, delete line (no print)
sed -e '1p;$p;d' YourFile

用awk:

 # print first, remind last line read, at the end print last know line
 awk '1;{last=$0};END{print $0)' YourFile

 # but you can work on content like
 awk '1{for(f=1;f<=NF;f++)h[i]=$1};{last=$0};END{split($0,a);for( j in h) printf( "%d:%s -> %s\n", j, h[j], a[j])}' YourFile

这取决于你想做什么(下一个)