This example shows how to read a specific field (field) from a data file in a Linux shell script and manipulate it. For example, suppose the format of the file Employees.txt is {employee-name}:{employee-id}:{department-name}, separated by a colon, as shown below.
$ cat Employees.txt
Emma thomas:100:marketing
Alex Jason:200:sales
Madison randy:300:product Development
Sanjay Gupta:400:support
Nisha Singh:500:sales
The following shell script shows how to read a specific field (field) from this employee.txt file.
$ VI read-employees.sh
#!/bin/bash
Ifs=:
echo "Employee Names:"
echo "---------------"
While read name Empid dept
Todo
echo "$name is part of $dept Department"
Done < ~/employees.txt
Execute this script after giving the script executable permissions
$ chmod u+x read-employees.sh
$./read-employees.sh
Employee Names:
Note: In Linux shell is a good command to facilitate our use, but also convenient for hackers to use, so we should pay attention to the shell security and permissions on the set OH.