问题描述
我需要一个bash脚本来打印文件夹和文件的名称递归(沙田民政事务处中/ P)。
例如:
我有一个文件夹结构,像/earth/plants/flowers/rose/rose.jpg。
/earth/plant/fruits/apple/apple.jpg。
/earth/animals/carni/lions.jpg
/earth/animals/herbi/omni/dog.jpg
现在我需要列出此文件和文件夹像这样我的意思是我的O / P脚本应该是
=行星地球
类别=动物(植物)
子猫= CARNI
名称= lion.jpg。
我试图
`查找/ -name*-print | awk的-F/'{打印\\ n星球=$ 2\\ n类=,$ 3,\\ n个子猫=$ 4,\\ n NAME =,$ 5,$ 6}'`
上面的命令给了我下面的O / P。
=行星地球
类别=动物(植物)
子猫= CARNI
名称= lion.jpg
但在某些情况下,我像其他文件夹在这种情况下,为了 /earth/animals/herbi/omni/rabbit.jpg
在这样的输出正在发生变化:
=行星地球
类别=动物
子猫= herbi
NAME =全
rabbit.jpg
所以我需要列举其他SUBCAT在几个地方。像
=行星地球
类别=动物
子猫= herbi
加上猫=全
名称= rabbit.jpg
所以该怎么做跟单script.Scripts除了AWK也是欢迎的。
`查找/ -name*-print | awk的-F/'{打印\\ n星球=$ 2\\ n类=,$ 3,\\ n个子猫=$ 4,\\ n NAME =,$ 5,$ 6}``
在这种情况下,什么5 $曾经有将打印姓名only.so需要这样的事情。
``查找/ -name*-print | awk的-F/'{打印\\ n星球=$ 2\\ n类=$ 3,\\ n个子猫=$ 4,\\ n添加猫=$ 5,(如果5 $ = FOLDERNAME打印增加猫咪=全)的名称= $ 6}'``。
谢谢,
vijai氏/ P>
的awk -F/'{
打印\\ n星球=$ 2\\ n类=,$ 3,\\ n个子猫=$ 4个
对于(i = 5; I< NF;我++)打印增加猫咪=$ I
打印NAME =$ NF
}
I need a bash script to print folder names and file names recursively (in stdo/p).For example:i have a folders structure like /earth/plants/flowers/rose/rose.jpg.
/earth/plant/fruits/apple/apple.jpg.
/earth/animals/carni/lions.jpg
/earth/animals/herbi/omni/dog.jpg
now i need to list this files and folders like this i mean my O/P script should be,
planet=earth
category=animal (plant)
sub cat = carni
name = lion.jpg.
i tried
`find / -name "*" -print | awk -F"/" '{ print "\n planet=",$2,"\n category=",$3,"\n sub cat=",$4,"\n Name=",$5, $6 }'`
above command gives me following O/P.
planet=earth
category=animal (plant)
sub cat = carni
name = lion.jpg
But in some cases i've additional folders like "/earth/animals/herbi/omni/rabbit.jpg
" in this case order is changing in output like:
planet=earth
category=animal
sub cat = herbi
name = omni
rabbit.jpg
so i need to list additional subcat in few places . like
planet=earth
category=animals
sub cat = herbi
add cat = omni
name = rabbit.jpg
so how to do that with a single script.Scripts apart from awk is also welcome.
`find / -name "*" -print | awk -F"/" '{ print "\n planet=",$2,"\n category=",$3,"\n sub cat=",$4,"\n Name=",$5,$6}``
in this case what ever there in $5 it will print as name only.so need something like this.
``find / -name "*" -print | awk -F"/" '{ print "\n planet=",$2,"\n category=",$3,"\n sub cat=",$4,"\n add cat =",$5,(if $5 = foldername print "add cat = omni") name = $6 }'"``.
thanks,vijai k
awk -F"/" '{
print "\n planet=", $2, "\n category=", $3, "\n sub cat=", $4
for (i = 5; i < NF; i++) print " add cat=", $i
print " Name=",$NF
}'
这篇关于需要bash脚本和awk命令的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!