In Linux, read the specified field of the data file to the shell script.
Source: Internet
Author: User
This example shows how to read and operate a specific field from a data file in a shell script in Linux. For example, the format of the hypothetical file employees.txt is {employee-name }:{ employee-id }:{ departm... this example shows how to read and operate a specific field from a data file in a shell script in Linux. For example, the format of the hypothetical file employees.txt is {employee-name }:{ employee-id }:{ department-name}, which is divided by a colon, as shown below. Www.2cto.com $ cat employees.txt Emma Thomas: 100: Marketing Alex Jason: 200: Sales Madison Randy: 300: Product Development Sanjay Gupta: 400: Support Nisha Singh: 500: the shellscript in the Sales section describes how to read a specific field from the employee.txt file ). $ Vi read-employees.sh #! /Bin/bash IFS =: echo "Employee Names:" echo "---------------" while read name empid dept do echo "$ name is part of $ dept department" done <~ /Employees.txt grant the script executable permission to execute the script www.2cto.com $ chmod u + x read-employees.sh $. /read-employees.sh Employee Names: --------------- Emma Thomas is part of Marketing department Alex Jason is part of Sales department Madison Randy is part of Product Development department Sanjay Gupta is part of Support department Nisha Singh is part of Sales department
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service