亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: 『求助』文件名匹配問題 [打印本頁]

作者: 另一只    時間: 2005-11-25 12:04
標題: 『求助』文件名匹配問題
有如下文件:
CHARBASE046.MYD
CHARBASE046.MYI
CHARBASE047.frm
CHARBASE047.MYD
CHARBASE047.MYI
CHARBASE048.frm
CHARBASE048.MYD
CHARBASE048.MYI
CHARBASE049.frm
CHARBASE049.MYD
CHARBASE049.MYI
CHARBASE.frm
CHARBASE.MRG

要將其中CHARBASE.* 和 CHARBASE049.*所有文件拷貝到其他目錄,
請問在命令行下怎樣用正則表達式匹配這5個文件名,如果不考慮使用管道,應該怎么寫這個命令?
謝謝
作者: 寂寞烈火    時間: 2005-11-25 12:11

  1. ls /path CHARBASE.* CHARBASE049.*|xargs -i cp {} /otherpath
復制代碼

作者: waker    時間: 2005-11-25 12:33
cp  CHARBASE{,049}.* otherpath/
作者: 寂寞烈火    時間: 2005-11-25 12:36
原帖由 waker 于 2005-11-25 12:33 發(fā)表
cp  CHARBASE{,049}.* otherpath/

原來還可以這樣 `~~`
作者: luosfu    時間: 2005-11-25 13:03
原帖由 寂寞烈火 于 2005-11-25 12:11 發(fā)表

  1. ls /path CHARBASE.* CHARBASE049.*|xargs -i cp {} /otherpath
復制代碼


我還是喜歡這種用法
作者: 另一只    時間: 2005-11-25 14:15
多謝各位幫助 感激不盡啊。
想了很久就是不知道寫。

waker 的用法很經(jīng)典,剛才用了果然可以。
原帖由 waker 于 2005-11-25 12:33 發(fā)表
cp  CHARBASE{,049}.* otherpath/


可否解釋一下{,049}中逗號的用法,以前從來沒有看到過這個元字符,孤陋寡聞,還望點撥一下。




另外{,049}.* 中那個.號在這里到時普通的字符還是匹配符,*號在這里到底是普通意思上的匹配還是正則表達式中的匹配?  看著這.*越看越糊涂。

[ 本帖最后由 另一只 于 2005-11-25 15:26 編輯 ]
作者: 另一只    時間: 2005-11-26 10:57
兄弟們,麻煩指點一下,發(fā)現(xiàn)下面的命令也可以:
cp  CHARBASE{,049}.** otherpath/     就是弄不明白, . * 的意思

引申一下:
要是文件如下
CHARBASE046.MYD
CHARBASE046.MYI
CHARBASE047.frm
CHARBASE047.MYD
CHARBASE047.MYI
CHARBASE048.frm
CHARBASE048.MYD
CHARBASE049049.MYI
CHARBASE049.frm
CHARBASE049.MYD
CHARBASE049.MYI
CHARBASE.frm
CHARBASE.MRG

用正則表達式一次匹配復制上面6個藍色文件名,該怎么寫命令啊


[ 本帖最后由 另一只 于 2005-11-29 18:26 編輯 ]
作者: 寂寞烈火    時間: 2005-11-26 12:58
man bash,見 Brace Expansion 段的描述
作者: 另一只    時間: 2005-11-29 15:48
謝謝樓上兄弟
作者: 另一只    時間: 2005-11-29 17:43
Brace Expansion
       Brace expansion is a mechanism by which arbitrary strings may be gener-
       ated.  This mechanism is similar to pathname expansion, but  the         file-
       names generated need not exist.        Patterns to be brace expanded take the
       form of an optional preamble, followed by a series  of  comma-separated
       strings        between         a pair of braces, followed by an optional postscript.
       The preamble is prefixed to each string contained  within  the  braces,
       and the postscript is then appended to each resulting string, expanding
       left to right.

       Brace expansions may be nested.        The results of        each  expanded        string
       are  not         sorted;  left        to  right  order  is  preserved.  For example,
       a{d,c,b}e expands into `ade ace abe'.

       Brace expansion is performed before any other expansions, and any char-
       acters  special to other expansions are preserved in the result.         It is
       strictly textual.  Bash does not apply any syntactic interpretation  to
       the context of the expansion or the text between the braces.

       A  correctly-formed  brace  expansion must contain unquoted opening and
       closing braces, and at  least  one  unquoted  comma.   Any  incorrectly
       formed  brace expansion is left unchanged.  A { or , may be quoted with
       a backslash to prevent its being considered part of a brace expression.
       To  avoid conflicts with parameter expansion, the string ${ is not con-
       sidered eligible for brace expansion.

       This construct is typically used as shorthand when the common prefix of
       the strings to be generated is longer than in the above example:

              mkdir /usr/local/src/bash/{old,new,dist,bugs}
       or
              chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}

       Brace  expansion         introduces  a        slight incompatibility with historical
       versions of sh.        sh does not treat opening or closing braces  specially
       when  they  appear as part of a word, and preserves them in the output.
       Bash removes braces from words as a  consequence         of  brace  expansion.
       For  example,  a word entered to sh as file{1,2} appears identically in
       the output.  The same word is output as file1 file2 after expansion  by
       bash.   If strict compatibility with sh is desired, start bash with the
       +B option or disable brace expansion with the +B option to the set com-
       mand (see SHELL BUILTIN COMMANDS below).
作者: 另一只    時間: 2005-11-29 17:44
幫助里面還是沒有講很清楚。

[ 本帖最后由 另一只 于 2005-11-29 18:38 編輯 ]
作者: 另一只    時間: 2005-11-29 18:41
要是文件如下
CHARBASE046.MYD
CHARBASE046.MYI
CHARBASE047.frm
CHARBASE047.MYD
CHARBASE047.MYI
CHARBASE048.frm
CHARBASE048.MYD
CHARBASE049049.MYI
CHARBASE049.frm
CHARBASE049.MYD
CHARBASE049.MYI
CHARBASE.frm
CHARBASE.MRG

用正則表達式一次匹配復制上面6個藍色文件名,該怎么寫命令啊
----------------------------------------
我是這么寫的
    cp ../Titan/CHARBASE{,049}{,049}.* .
確實可以copy成功,但是系統(tǒng)提示警告:
cp: warning: source file `../Titan/CHARBASE049.MYD' specified more than once
cp: warning: source file `../Titan/CHARBASE049.MYI' specified more than once
cp: warning: source file `../Titan/CHARBASE049.frm' specified more than once
還是不清楚 , . * 具體指待的意思
作者: waker    時間: 2005-11-29 19:00
這個不是正則表達式,是大概括擴展
使用shell的-x選項觀察一個就知道發(fā)生了什么

  1. root@sarge:~# set -vx
  2. set -vx
  3. root@sarge:~# echo {1,2}
  4. echo {1,2}
  5. + echo 1 2
  6. 1 2
  7. root@sarge:~# echo {1,2}{a,b,c}
  8. echo {1,2}{a,b,c}
  9. + echo 1a 1b 1c 2a 2b 2c
  10. 1a 1b 1c 2a 2b 2c
  11. root@sarge:~# echo {1,2}\ {a,b,c}
  12. echo {1,2}\ {a,b,c}
  13. + echo '1 a' '1 b' '1 c' '2 a' '2 b' '2 c'
  14. 1 a 1 b 1 c 2 a 2 b 2 c
  15. root@sarge:~# echo {1,2} {a,b,c}
  16. echo {1,2} {a,b,c}
  17. + echo 1 2 a b c
  18. 1 2 a b c
復制代碼

作者: 另一只    時間: 2005-12-01 16:54
老大,我終于懂了。  非常感謝。!




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2