 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
 