- 论坛徽章:
- 2
|
回复 1# Windows19
提供一种方法,希望有帮助- [root@study study]# ls
- file file1 script.sh temp
- [root@study study]# cat file file1
- afe()';.,]][0
- 123()';.,]][0
- [root@study study]#
- [root@study study]#
- [root@study study]# cd temp/
- [root@study temp]# ls
- 123()';.,]][0 afe()';.,]][0
- [root@study temp]# cd ..
- [root@study study]# sh script.sh
- [root@study study]# cat file file1
- afe()';.,]][0
- 123()';.,]][0
- www
- ww
- a
- aaa
- aa
- [root@study study]# cat script.sh
- #!/bin/sh
- alias ll='ls -l'
- LANG=C
- export LANG
- Line=`ll /tmp/study/temp | grep -v total | wc -l`
- export Line
- declare -x num
- num=1
- while :
- do
- var=`ll /tmp/study/temp | grep -v total | head -n $num |tail -n 1| awk '{print $9}'`
- export var
- for i in `cat /tmp/study/file`
- do
- if [ "$i" = "$var" ];then
- cd /tmp/study/temp
- cat ${var} >> /tmp/study/file1
- echo >> /tmp/study/file1
- break 1
- else
- continue
- fi
- done
- num=$(($num+1))
- if [ $num -gt $Line ];then
- break
- fi
- done
复制代码 其中,这个底下部分,貌似只能用这种方式。我本想用cat /tmp/study/temp/${var},但是会提示无此文件。
cd /tmp/study/temp
cat ${var} >> /tmp/study/file1
|
评分
-
查看全部评分
|