The input file input_file is the name of the file redirected to the while loopThe read command processes the file line by line assigning each line to the line variable.
How to read text files in linux. Do echo -e linen. Use redirection operators to fetch the data from the stdout and stderr streams and redirect them to a text file. Your data file likely has rn especially if created on Windows.
How does it work. The -r option passed to read command prevents backslash escapes from being interpreted. You can simply use the cat command and display back output on screen.
Add IFS option before read command to prevent leadingtrailing whitespace from being trimmed - while IFS read -r line. How can i do this shell scripting. By default the read command interprets the backslash as an escape character and removes all leading and trailing white spaces which sometimes may.
If you open a file in default text mode on Windows rn is translated to n when read. If you want to read each line of a file by omitting backslash escape then you have to use -r option with read command in while loop. Less RESULTStxt If you want to read and edit the text file from the same directory type.
While read line do command done. I have list of files in a directory dir. The syntax is as follows for bash ksh zsh and all other shells to read a file line by line.
This is line 1 This is line 2 This is line 3 This is line 4 This is line 5. Use Universal newline mode instead. When using redirection to create a file take care not to delete a significant existing file.