[英]Extract information from file in format " nameofthefile:owner:permissions(numeric):size(in MB) " from the file below using sed or awk or grep
File: /boot/initrd.img-5.4.0-74-generic文件:/boot/initrd.img-5.4.0-74-generic
Size: 86873155 Blocks: 169680 IO Block: 4096 regular file大小:86873155 块:169680 IO 块:4096 常规文件
Device: 805h/2053d Inode: 1046537 Links: 1设备:805h/2053d 索引节点:1046537 链接:1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)访问:(0644/-rw-r--r--) Uid:(0/root) Gid:(0/root)
Access: 2021-11-27 19:50:34.418351977 +0100访问:2021-11-27 19:50:34.418351977 +0100
Modify: 2021-11-27 19:50:33.890335620 +0100修改:2021-11-27 19:50:33.890335620 +0100
Change: 2021-11-27 19:50:34.410351729 +0100更改:2021-11-27 19:50:34.410351729 +0100
Birth: -出生: -
File: /boot/grub/unicode.pf2文件:/boot/grub/unicode.pf2
Size: 2395475 Blocks: 4680 IO Block: 4096 regular file大小:2395475 块:4680 IO 块:4096 常规文件
Device: 805h/2053d Inode: 1046539 Links: 1设备:805h/2053d 索引节点:1046539 链接:1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)访问:(0644/-rw-r--r--) Uid:(0/root) Gid:(0/root)
Access: 2021-07-03 19:31:12.000000000 +0200访问:2021-07-03 19:31:12.000000000 +0200
Modify: 2021-11-27 19:51:54.612537152 +0100修改:2021-11-27 19:51:54.612537152 +0100
Change: 2021-11-27 19:51:54.612537152 +0100更改:2021-11-27 19:51:54.612537152 +0100
Birth: -出生: -
Try this awk
试试这个
awk
% awk '/File:/{ n=split($2,arr,"/"); print "filename:",arr[n] }
/Access:.*Uid/{ gsub("\(|/.*","",$2); sub("\)","",$6);
print "owner:",$6"\npermissions:",$2 }
/Size:/{ print "size(Mb):",$2*0.000488281 }
/Birth/{print "------"}' file | column -t
filename: initrd.img-5.4.0-74-generic
size(Mb): 42418.5
owner: root
permissions: 0644
------
filename: unicode.pf2
size(Mb): 1169.66
owner: root
permissions: 0644
------
% cat file
File: /boot/initrd.img-5.4.0-74-generic
Size: 86873155 Blocks: 169680 IO Block: 4096 regular file
Device: 805h/2053d Inode: 1046537 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2021-11-27 19:50:34.418351977 +0100
Modify: 2021-11-27 19:50:33.890335620 +0100
Change: 2021-11-27 19:50:34.410351729 +0100
Birth: -
File: /boot/grub/unicode.pf2
Size: 2395475 Blocks: 4680 IO Block: 4096 regular file
Device: 805h/2053d Inode: 1046539 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2021-07-03 19:31:12.000000000 +0200
Modify: 2021-11-27 19:51:54.612537152 +0100
Change: 2021-11-27 19:51:54.612537152 +0100
Birth: -
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.