【发布时间】:2017-04-26 10:36:03
【问题描述】:
我是 shell 脚本的新手。我需要读取 csv 页眉和页脚的 shell 脚本。 谢谢
【问题讨论】:
-
head -1和tail -1
我是 shell 脚本的新手。我需要读取 csv 页眉和页脚的 shell 脚本。 谢谢
【问题讨论】:
head -1 和 tail -1
为了快速,两个文本文件操作的基本工具: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
这取决于你想做什么(下一步)
【讨论】: