要求:我只需要使用public class rootClass
{
public string string took {get;Set;}
public string timeout {get;Set;}
public Shards shards {get;Set;}
public OuterHits hits {get;Set;}
}
/ grep
/ cut
。
我有类似的数据:
join
我想将此数据通过管道传递到 3 abcd
23 xyz
1234 abc
,然后提取列。但是,当我使用cut
时,它将每个空间视为自己的列分隔符。我希望在cut -d' ' -f 1,2
之前修剪前两行。有办法吗?
示例(我已经使用cut
来演示此处的空格;解决方案中不允许这样做):
tr
预期输出:
$ echo ' 3 abcd
23 xyz
1234 abc' | cut -d' ' -f 1,2 | tr ' ' '_'
_
_23
1234_abc
答案 0 :(得分:0)
仅使用grep
,您可以通过以下管道完成此操作:
grep -oe "[^ ][^ ]* *[^ ][^ ]*$"
grep # a tool for matching text
-o # only prints out matching text
-e # uses a regex
[^ ] # match anything that isn't a space
* # match zero or more of the previous element
$ # the end of the line
注意:这不考虑尾随空格。
演示:
$ echo ' 3 abcd
23 xyz
1234 abc' | grep -oe "[^ ][^ ]* *[^ ][^ ]*$"
3 abcd
23 xyz
1234 abc