Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用sed,如何匹配字符类中的方括号?_Sed - Fatal编程技术网

使用sed,如何匹配字符类中的方括号?

使用sed,如何匹配字符类中的方括号?,sed,Sed,下面是一大块原始数据: 00000000 54 6f 70 69 63 20 46 6f 72 75 6d 20 52 65 70 6c |Topic Forum Repl| 00000010 69 65 73 20 4c 61 73 74 20 70 6f 73 74 20 31 20 |ies Last post 1 | 00000020 4c 69 6e 75 78 20 54 6f 64 61 79 20 31 34 3a 34 |Linux Today 14:4| 0

下面是一大块原始数据:

00000000  54 6f 70 69 63 20 46 6f  72 75 6d 20 52 65 70 6c  |Topic Forum Repl|
00000010  69 65 73 20 4c 61 73 74  20 70 6f 73 74 20 31 20  |ies Last post 1 |
00000020  4c 69 6e 75 78 20 54 6f  64 61 79 20 31 34 3a 34  |Linux Today 14:4|
00000030  36 3a 35 37 20 62 79 20  4c 69 6e 75 78 20 4f 75  |6:57 by Linux Ou|
00000040  74 6c 61 77 73 20 32 36  39 20 e2 80 93 20 53 6f  |tlaws 269 ... So|
00000050  6d 65 6f 6e 65 20 4b 6c  6f 73 65 20 54 68 61 74  |meone Klose That|
00000060  20 4f 75 74 6c 61 77 73  20 32 38 20 73 79 73 79  | Outlaws 28 sysy|
00000070  70 68 75 73 2e 6a 6f 6e  65 73 20 48 6f 6c 65 20  |phus.jones Hole |
00000080  62 79 20 59 4f 42 41 20  5b 20 31 20 32 20 5d 20  |by YOBA [ 1 2 ] |
00000090  32 20 4c 69 6e 75 78 20  26 20 54 6f 64 61 79 20  |2 Linux & Today |
000000a0  31 31 3a 34 34 3a 35 31  20 62 79 20 4c 6f 6f 6b  |11:44:51 by Look|
000000b0  73 20 6c 69 6b 65 20 43  61 6e 6f 6e 69 63 61 6c  |s like Canonical|
000000c0  20 69 73 20 61 6e 6e 6f  75 63 69 6e 67 20 70 6c  | is annoucing pl|
000000d0  61 6e 73 20 46 72 65 65  64 6f 6d 20 31 20 6b 72  |ans Freedom 1 kr|
这是一个十六进制转储,我对隔离文本部分感兴趣。 下面是一个几乎可以工作的sed表达式:

$ sed 's/.* |\([a-zA-Z0-9:& \.]*\)|$/\1/g' hex.dat 
Topic Forum Repl
ies Last post 1 
Linux Today 14:4
6:57 by Linux Ou
tlaws 269 ... So
meone Klose That
 Outlaws 28 sysy
phus.jones Hole 
00000080  62 79 20 59 4f 42 41 20  5b 20 31 20 32 20 5d 20  |by YOBA [ 1 2 ] |
2 Linux & Today 
11:44:51 by Look
s like Canonical
 is annoucing pl
ans Freedom 1 kr
差不多。但是如何过滤最后一行呢

$ sed 's/.* |\([a-zA-Z0-9:&\[\] \.]*\)|$/\1/g' hex.dat 
以及:

根本不工作(他们什么都不会翻译)

以及:

显然不行

谢谢你的帮助。

你几乎成功了

请看a的这一部分

你的方法是在你开始你的角色课程后立即放置]

因此,请尝试使用sed's/*\([[a-zA-Z0-9:&.]*\])\$/\1/g'hex.dat

为了澄清,只要您要包含在角色类中的结束括号(
]
)紧跟在角色类的开始之后,那么
[
在角色类中的位置并不重要

另外,作为进一步的编辑,试着键入
mancut
并使用Tomasz在评论中所说的内容


cut-d='|'-f2 hex.dat
将剪切您的文件,在管道上划界,并获取第二个字段。

cut-d'|'-f2 hex.dat这样简单的东西怎么样?
?非常整洁的Tomasz。我有时会把事情复杂化:)但我很高兴twmb的答案作为参考。谢谢twmb…(我)离得这么近,但到目前为止:)
    $ sed 's/.* |\([a-zA-Z0-9:&\\[\\] \.]*\)|$/\1/g' hex.dat 
$ sed 's/.* |\([a-zA-Z0-9:&[] \.]*\)|$/\1/g' hex.dat