在这个程序中,我们被给定一个文件名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.
$> awk ‘{if(NR==5) print $0}’ text.txt
$>sed -n 5p text.txt
$head -n 5 filename | tail - n + 5
The above is the detailed content of Write a bash script in C language that prints specific lines in a file. For more information, please follow other related articles on the PHP Chinese website!