偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Linux下將數(shù)據(jù)文件的指定域讀取到shell腳本中

運(yùn)維 系統(tǒng)運(yùn)維
這個(gè)例子說明了怎樣在Linux下shell腳本中從數(shù)據(jù)文件讀取特定的域(field)并進(jìn)行操作。例如,假設(shè)文件employees.txt的格式是{employee-name}:{employee-id}:{department-name},以冒號進(jìn)行劃分,如下所示。

這個(gè)例子說明了怎樣在Linux下shell腳本中從數(shù)據(jù)文件讀取特定的域(field)并進(jìn)行操作。例如,假設(shè)文件employees.txt的格式是{employee-name}:{employee-id}:{department-name},以冒號進(jìn)行劃分,如下所示。

$ cat employees.txt 
Emma Thomas:100:Marketing 
Alex Jason:200:Sales 
Madison Randy:300:Product Development 
Sanjay Gupta:400:Support 
Nisha Singh:500:Sales

下面的shell腳本說明了如何從這個(gè)employee.txt文件中讀取特定的域(field)。

$ 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

賦予腳本可執(zhí)行權(quán)限后執(zhí)行該腳本

$ 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

 

【編輯推薦】

  1. Clojure世界:如何做性能測試
  2. Linux服務(wù)器的16個(gè)監(jiān)控命令
  3. IE8安全新功能實(shí)測,到底給不給力?
責(zé)任編輯:趙寧寧
相關(guān)推薦

2021-08-20 10:46:25

Shell腳本文件Linux

2021-04-21 08:03:34

腳本Shell讀取

2009-12-03 10:06:33

Ubuntushell腳本

2010-07-13 14:09:07

SQL Server數(shù)

2022-08-30 08:52:04

shell腳本Linux

2015-07-16 17:13:13

shell分頁讀取MySQL數(shù)據(jù)腳本

2017-12-18 10:12:48

LinuxShell命令

2011-08-03 11:11:01

本地組腳本

2024-11-27 09:19:25

2010-03-23 16:35:31

shell 腳本編程

2024-02-19 16:15:07

2020-05-28 15:35:21

Linux數(shù)據(jù)文件圖像

2016-12-16 09:23:29

LinuxShell腳本

2013-08-07 10:04:37

MySQL數(shù)據(jù)恢復(fù)

2017-10-11 16:23:59

Linuxinode刪除文件

2010-10-29 14:03:39

Oracle移動(dòng)數(shù)據(jù)文

2017-08-25 17:41:17

Paradox數(shù)據(jù)文件格式

2010-10-13 14:02:01

MySQL數(shù)據(jù)文件

2010-04-30 16:01:17

2018-11-12 14:35:47

BashhereLinux
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號