read file in linux code example

Example 1: read file using shell script

#!/bin/bash
input="/path/to/txt/file"
while IFS= read -r line
do
  echo "$line"
done < "$input"

Example 2: linux command to view file

cat command.
less command.
more command.
"gnome-open command" or "xdg-open command" (generic version) or "kde-open command" (kde version)Linux gnome/kde desktop command to open any file.
open command – OS X specific command to open any file.

Example 3: linux check file contetns

cat "fileName"

Tags:

Java Example