From the course: Learning Bash Scripting
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Reading and writing text files - Bash Tutorial
From the course: Learning Bash Scripting
Reading and writing text files
To write to text files from a Bash script, we'll use output redirection, which we saw briefly earlier in the course. The two primary operators we'll use here are the single and double greater than signs. The single greater than sign stands for redirection, where the existing information in the destination file gets replaced with the new information from whatever operation is writing the information, and the double greater than signs represent the existing information in the destination file being preserved, with new information added or appended to the end of the file. To read from files, we'll use the input redirection operator to use a text file as input for the read keyword with a while loop, which will read the text file line by line, giving us the opportunity to use each line in turn within the while loop. Let's write a basic script that will output a few lines of text to a file. I'll open my script and clean it out. I'll write a for loop with for i in 1, 2, 3, 4, 5. And for each…
Contents
-
-
-
-
-
(Locked)
Conditional statements with the "if" keyword4m 32s
-
(Locked)
Working with while and until loops3m 56s
-
(Locked)
Introducing "for" loops5m 55s
-
(Locked)
Selecting behavior using "case"2m 8s
-
(Locked)
Using functions7m 6s
-
(Locked)
Reading and writing text files3m 59s
-
(Locked)
Challenge: Build a script using control structures31s
-
(Locked)
Solution: Build a script using control structures1m 39s
-
(Locked)
-
-
-