如何读取从线X文件在bash一个文件的最后 [英] how to read file from line x to the end of a file in bash

查看:99
本文介绍了如何读取从线X文件在bash一个文件的最后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我可以从第二行的文件在bash脚本到底读了<$​​ C $ C> CSV 文件中的每一行。

我知道如何阅读在bash的文件:

 而读线
 做
   回声-e$行\\ n
完成&LT; FILE.CSV

但是,我想读从第2行到文件的结尾处开始的文件。我怎样才能做到这一点?


解决方案

 尾-n +2 FILE.CSV

手册页

  -n,--lines = N
     输出的最后N行的,而不是最后10
...如果由N(字节或行数)的第一个字符是一个+,
打印与来自每个文件的开头的第N项开始的,否则
明智的,打印的文件中的最后N项。

在英国,这意味着:

尾-n 100 打印最后100行

尾-n +100 打印从行100开始的所有行

I would like know how I can read each line of a csv file from the second line to the end of file in a bash script.

I know how to read a file in bash:

while read line
 do   
   echo -e "$line\n"
done < file.csv

But, I want to read the file starting from the second line to the end of the file. How can I achieve this?

解决方案

tail -n +2 file.csv

From the man page:

-n, --lines=N
     output the last N lines, instead of the last 10
...

If the first character of N (the number of bytes or lines)  is  a  '+',
print  beginning with the Nth item from the start of each file, other-
wise, print the last N items in the file.

In English this means that:

tail -n 100 prints the last 100 lines

tail -n +100 prints all lines starting from line 100

这篇关于如何读取从线X文件在bash一个文件的最后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆