请教linux 脚本操作

ak_kay 2011-12-10 03:52:02
A目录:
20111210-13.txt
B目录:
...
20111210-11.txt
20111210-12.txt
20111210-13.txt
20111210-14.txt
20111210-15.txt
...
有什么方法通过A目录下的-13文档,匹配B目录20111210-13.txt,并打印及其以后的文档(即13,14,15...)出来;

说明,B目录文档可能不按以上例子顺序,不过最终结果都是(13,14,15...)
...全文
94 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
agustawestland 2011-12-12
  • 打赏
  • 举报
回复
sed -n "/$fileA/,\$p"

能否解释一下!!!
askandstudy 2011-12-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ljc007 的回复:]

Assembly code
fileA=`ls ./a`
ls -1 ./b | sed -n "/$fileA/,\$p"
[/Quote]

学习了
ljc007 2011-12-12
  • 打赏
  • 举报
回复
fileA=`ls ./a`
ls -1 ./b | sed -n "/$fileA/,\$p"
askandstudy 2011-12-10
  • 打赏
  • 举报
回复

[root@RHEL6A shcode]# ls /tmp/A
20111210-13.txt
[root@RHEL6A shcode]# ls /tmp/B
20111210-11.txt 20111210-12.txt 20111210-13.txt 20111210-14.txt 20111210-15.txt
[root@RHEL6A shcode]# cat sh14.sh
#!/bin/bash
dira='/tmp/A'
dirb='/tmp/B'
for i in `ls $dira`
do
ds=`ls $dirb`
ds2=`echo $ds|grep "$i"`
if [ "$ds2" != "" ]
then
echo $i ${ds#*$i}
fi
done

[root@RHEL6A shcode]# ./sh14.sh
20111210-13.txt 20111210-14.txt 20111210-15.txt
[root@RHEL6A shcode]#
askandstudy 2011-12-10
  • 打赏
  • 举报
回复
大概试了下好像可以,你试试看,不行再改改。


#!/bin/bash
for i in `ls /tmp/log`
do
#echo $i
ds=`ls /tmp`
ds2=`echo $ds|grep "$i"`
if [ "$ds2" != "" ]
then
#echo $ds2
echo $i ${ds#*$i}
fi
#${ds/*$i/$i} && echo $result || echo ''
done