Shell Scripting Tutorial for Beginners 17 - Read a file content in Bash

preview_player
Показать описание
How do I read a text file line by line under a Linux or UNIX-like system using BASH shell?
You can use while..do..done bash loop to read file line by line on a Linux, OSX, or Unix-like system.
There are basically three ways to read file content using bash.
1a: While loop: Single line at a time: Input redirection.
1b: While loop: Single line at a time:
Open the file, read from a file descriptor (in this case file descriptor #4).
2: While loop: Read file into single variable and parse.

★★★Top Online Courses From ProgrammingKnowledge ★★★

★★★ Online Courses to learn ★★★

★★★ Follow ★★★

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!
Рекомендации по теме
Комментарии
Автор

We can also use the below script to read a file:-

#! /bin/bash

echo -e "Enter your file name \c"
read p

cat $p

I think it is simple

deepakranjan
Автор

Can you brief us applications of IFS using any example....in this video we couldn't understand the purpose of IFS as output for all the cases are same ....:)

ajithreddy
Автор

Excellent to understand the basics. Thank you!

dasvtx
Автор

I have a simple question: you are assigning space to IFS, from my understanding space becomes the only separator right? Why does it split at new lines rather than spaces in the output?

n_lisper
Автор

Is there any way to read raws or collumns or specific parts of a text file separately? that could be useful.

tsilivisgeo
Автор

But why would one use "while" to read the file, when it can be done easily in one step....

nitinvishwakarma
Автор

can you please explain the use of 'IFS' briefly

sudhanshurr
Автор

The IFS= has to be assigned before the while loop in my case in order to have an effect against wildcards in the script.

ctrnwom
Автор

how to read this file into an array instead of a while loop?
Thanks for the tutorial

rakotondrasoahary
Автор

How to input current directory/ current files into while loop

asadasivam
Автор

its aprli 1st, i don't trust anything

sansactionl
Автор

turn speed up to 1, 25. Save up your precious time xD

Shiba_Kafka
Автор

Did not understand tthis lecture....explaianation wasnt good

amandeepgera
welcome to shbcf.ru