ÇëÎÊÒ»¸ö¹ØÓÚÎļþ¸ÄÃûµÄÎÊÌâ
ij¸öĿ¼ÏÂÃæÓÐһЩÎļþ£¬ÎÒÏë°ÑijЩ¾ßÓÐÌØ¶¨¹Ø¼ü×ÖµÄÎļþ¸ÄÃû£¬ÇëÎʸÃÈçºÎ´¦Àí£¿¾ßÌåµØËµ£¬±ÈÈçĿ¼ÏÂÓÐa.txt,_2_a.txt,_3_c.txtÎļþ,ÎÒÏë°ÑÒÔ"_"¿ªÍ·µÄÎļþÌáÈ¡³öÀ´µ¥¶À´¦Àí£ºÊ×ÏÈÏÈ´æÏÂÁ½¸ö"_"Ö®¼äµÄÊýÖµ×÷ΪÎļþ¼ÐÃû³Æ£¬ÔÙ°Ñɾ³ý"_*_"ǰ׺µÄ¸ÃÎļþ´æµ½Õâ¸öÎļþ¼ÐÏ£¬¾ÍÊÇ_2_a.txt±ä³É a.txt´æµ½/2/Îļþ¼ÐÏ£¬_3_c.txt±ä³É c.txt´æµ½/3/Îļþ¼ÐÏ¡£
ÇëÎʸÃÈçºÎ±à³Ì´¦Àí£¿Ð»Ð»£¡ ÊDz»ÊÇÓ¦¸ÃÊ×ÏÈ"for file in `find \-name "xx""` do"ÃüÁîÕÒµ½ËùÓеÄ_¿ªÍ·µÄÎļþ£¿µ«ÊÇÔõÃ´Ð´ÄØ£¿ i dont think its diffcult. try and then ask [QUOTE=dearvoid]i dont think its diffcult. try and then ask[/QUOTE]лл¡¡ÎÒÊÔÁËÁ½¸öСʱ£¬¿ÉÊÇÁ¬×î¼òµ¥µÄµÚÒ»²½£¬ÕÒµ½"_"¿ªÍ·µÄÎļþ¶¼Ã»ÓÐʵÏÖ¡£¡£ÒòΪ֮ǰ²»´óÁ˽âshell±à³Ì¡£ÄܸøµãÌáʾÂð£¿//bow [QUOTE=dearvoid]i dont think its diffcult. try and then ask[/QUOTE]ÎÒÊÔÁËÕâ¸ö£º
for file in *
do
case $file in
_*_* )
echo $file
;;
esac
done
¿ÉÒÔÌáÈ¡_2_a.txtÖ®ÀàµÄÎļþÁË£¬µ«ÊÇÔõô°Ñǰ׺ȥµô²¢ÇÒ´æÔÚ/2/ÏÂÄØ£¿ [code]
[0 No.2019 root@deb /tmp/work]# ls
_2_a.txt _3_c.txt
[0 No.2020 root@deb /tmp/work]# for f in _*;do
dir=$(echo $f | sed 's/_\(.*\)_.*/\1/')
file=$(echo $f | sed 's/.*_//')
mkdir $dir
mv $f $dir/$file
done
`_2_a.txt' -> `2/a.txt'
`_3_c.txt' -> `3/c.txt'
[0 No.2021 root@deb /tmp/work]# ls -R
.:
2/ 3/
./2:
a.txt
./3:
c.txt
[0 No.2022 root@deb /tmp/work]#
[/code] лл£¡ÕæµÄÊÇÓÃsed°¡¡£ÎÒÔÙÑо¿Ñо¿£¬//bow£¡ ÎÒÓýű¾ÕÒµ½ÁË_**_ÖмäµÄÊý×Ö£¬¿ÉÊÇmkdirµÄʱºò³ö´íÁË..ÎªÊ²Ã´ÄØ£¿³ÌÐò¾ÍÊÇÔÚÄãµÄ»ù´¡ÉÏ×÷ÁËС¸Ä¶¯¡£
for f in _*; do
echo "file" $f
dir = $(echo $f | sed 's/_\([0-9]*\)_.*/\1/')
echo "dir" $dir
file = $(echo $f | sed 's/.*|//')
mkdir $dir
#mv $f $dir/$file
done
ÔËÐнá¹ûÈçÏ£º
$./test
file _1_a.txt
dir: =:No such file or directory
dir: 1:No such file or directory
dir
=: cannot open `='(No such file directory)
mkdir: missing operand
try `mkdir --help' for more information.
[QUOTE=li-jiahuan][code]
[0 No.2019 root@deb /tmp/work]# ls
_2_a.txt _3_c.txt
[0 No.2020 root@deb /tmp/work]# for f in _*;do
dir=$(echo $f | sed 's/_\(.*\)_.*/\1/')
file=$(echo $f | sed 's/.*_//')
mkdir $dir
mv $f $dir/$file
done
`_2_a.txt' -> `2/a.txt'
`_3_c.txt' -> `3/c.txt'
[0 No.2021 root@deb /tmp/work]# ls -R
.:
2/ 3/
./2:
a.txt
./3:
c.txt
[0 No.2022 root@deb /tmp/work]#
[/code][/QUOTE] ÎÒ´íÁË¡¡=×óÓÒ²»ÄÜÓпոñ¡¡Ò»µÎº¹ Ò²²»ÊÇ·ÇÒªsed
there is more than one way to do it
[code]
[0 No.2002 huan@deb ~]$ str='_2_a.txt'
[0 No.2003 huan@deb ~]$ dir=${str/_/};dir=${dir%_*};echo $dir
2
[0 No.2004 huan@deb ~]$ file=${str##*_};echo $file
a.txt
[0 No.2005 huan@deb ~]$
[/code]
[code]
[0 No.2016 huan@deb ~]$ perl -e '$_ = "_2_a.txt"; print "dir: $1\nfile:$2\n" if (/_(.*)_(.*)/) '
dir: 2
file:a.txt
[0 No.2017 huan@deb ~]$
[/code]
Ò³:
[1]