我的输入文件是:
Employee
e_id e_name
100 abc
101 xyz
102 pqr
Salary
e_id e_salary
100 12345
101 67890
Dependents
e_id depp1 depp2
100 qwer tyui
102 asdf ghjkl
我想要逐行输出,如下所示:
E100abc
E101xyz
E102pqr
S10012345
S10167890
D100qwertyui
D102asdfghjkl
在输出中应该有起始字符,该字符将指示从哪个数据组获取此行数据。
答案1
for file in Employee Salary Dependents; do
prefix="${file:0:1}" # First character of the filename
sed "1,2d;s/ //;s/^/$prefix/" "$file"
done