我需要使用树命令..来创建文件raport,包括每个文件的开头内容,例如当前命令示例:
tree -hF
├── [129K] 219.137.24.130
│ └── [125K] gibi_gibi_member.csv
├── [5.7M] 219.142.104.84
│ ├── [ 43K] xshop_unihongbaorecord.csv
│ ├── [ 18K] xshop_zdmemberaddr.csv
│ ├── [2.2M] xshop_zdmember_copy.csv
│ ├── [2.6M] xshop_zdmember.csv
│ ├── [7.5K] xshop_zdmembertelinfo.csv
│ └── [877K] xshop_zdshareusersubmitinfo.csv
├── [9.9M] 219.84.203.57
│ ├── [259K] wealth_e_newsletter_subscriptions.csv
│ ├── [ 59K] wealth_orders.csv
│ └── [9.6M] wealth_users.csv
我想要这个输出:
├── [9.9M] 219.84.203.57
│ ├── [259K] wealth_e_newsletter_subscriptions.csv
./head 219.84.203.57/wealth_e_newsletter_subscriptions.csv
│ ├── [ 59K] wealth_orders.csv
./head 219.84.203.57/wealth_orders.csv
│ └── [9.6M] wealth_users.csv
./head 219.84.203.57/wealth_users.csv
我该怎么做?
答案 0 :(得分:0)
使用awk
和tree
的组合很容易做到:
tree -hFf | awk -v n=4 '1
{ file=$NF; sub($NF"$","");gsub(/./," ");
for(i=1;i<=n;++i) {getline var < file; print $0 var}
close(file) }'
此处n
表示文件应打印多少行。