Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Write a bash script to print a particular line from a file in C
In this program, we are given a file name text.txt. Our task is to print a particular line from the file.
For this there are multiple methods in bash script, they are awk, sed, head.
Syntax
$> 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
Using sed
$>sed -n 5p text.txt
Using head
$head -n 5 filename | tail - n + 5
Advertisements
