首页  >  文章  >  后端开发  >  编写一个在C语言中打印文件中特定行的bash脚本

编写一个在C语言中打印文件中特定行的bash脚本

WBOY
WBOY转载
2023-08-26 22:13:151272浏览

编写一个在C语言中打印文件中特定行的bash脚本

在这个程序中,我们被给定一个文件名text.txt。我们的任务是从文件中打印出特定的一行。

为了实现这个目标,bash脚本中有多种方法,它们是awk, sed, head

语法

$> awk ‘{if(NR==LINE_NUMBER) print $0}’ filename
$> sed -n LINE_NUMBERp filename
$head -n LineNumber filename | tail - n + LINE_NUMBER

Code to print a specific line in bash programming from file text.txt.

Using awk

$> awk ‘{if(NR==5) print $0}’ text.txt

使用sed命令

$>sed -n 5p text.txt

使用头部

$head -n 5 filename | tail - n + 5

以上是编写一个在C语言中打印文件中特定行的bash脚本的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除