【问题标题】:How to read CSV header in shell scripting如何在 shell 脚本中读取 CSV 标头
【发布时间】:2017-04-26 10:36:03
【问题描述】:

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

【问题讨论】:

  • head -1tail -1

标签: shell unix


【解决方案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

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

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 2019-02-10
    • 2016-07-25
    • 2017-03-24
    • 2023-04-01
    • 2015-10-23
    • 1970-01-01
    • 2012-02-02
    相关资源
    最近更新 更多