是否有一种方法可以找到模式中间并在狂欢中小写



我正在努力减少文本数据的大小。

示例输入:

example@EXAMPLE.com;example
example@EXAMPLE.com:exmaple

示例输出:

example@example.com;example
example@example.com:exmaple

伪代码:

if line has "@" and ":" or ";"
replace the text between @ and : or ; with lowercase

,但我甚至不知道要使用哪些工具。欢迎任何帮助。

使用 sed 工具解决此问题,

cat input_file.txt | sed -e 's/(.*@)([A-Za-z.]+)([;:].*)/1L23/' 

正则说明:

(。*@( - 此模式匹配'示例@

([a-za-z。] ( - 此模式匹配" example.com"

([;:]。或" exmaple"

l 更改为文本的小写

如果要更新内容使用 -i sed命令中的标志。

ex:

sed -i -e 's/(.*@)([A-Za-z.]+)([;:].*)/1L23/' input_file.txt

如果数据的数据 lot awk的速度将比外壳快。sed解决方案还可以,但这也有效:

$: awk '-F[;:]' '{ printf "%s;%sn", tolower($1), $2 }' x
example@example.com;exaMple
example@example.com;eXmaple
example@example.com;exAmple
example@example.com;exmaplE
example_example.com;Example
example_example.com;eXmaple
example@example.com,example;

-F IELD分离器定义为;:列表并降低第一个字段。我用标准化的;任意替换了定界符 - 如果那不起作用,这可能不是您的最佳解决方案。坚持使用sed

sprabhakaran在我最初打字时,用几乎相同的sed解决方案击败了我,大声笑。:(

sed can

$: cat x
Example@EXAMPLE.cOm;exaMple
exampLe@EXAMPLE.coM:eXmaple
example@EXAMPLE.com;example
example@EXAMPLE.com:exmaple
example_EXAMPLE.com;example
example_EXAMPLE.com:exmaple
example@EXAMPLE.com,example
$: sed -E '/@.+[;:]/s/^(.*)@(.*)([;:])(.*)/1@L2E34/' x
Example@example.com;exaMple
exampLe@example.com:eXmaple
example@example.com;exAmple
example@example.com:exmaplE
example_EXAMPLE.com;Example
example_EXAMPLE.com:eXmaple
example@EXAMPLE.com,examPle

L说要开始降低降低,直到 E(end(或 U(开始大量(。

此跳过没有@[;:](;:(的线条。

对于小数据集,本机bash可能更容易。

可能要简单得多,但是只要整理整个事情。

$: declare -l line
$: while read line
> do echo "$line"
> done < x
example@example.com;example
example@example.com:exmaple
example@example.com;example
example@example.com:exmaple
example_example.com;example
example_example.com:exmaple
example@example.com,example

declare -l使变量始终在其中放入任何内容。


由于对案例敏感的密码阻止了该密码,因此分别解析零件。

$: while IFS="$IFS:;" read email pass
> do echo "$email [$pass]"
> done < x
example@example.com [exaMple]
example@example.com [eXmaple]
example@example.com [exAmple]
example@example.com [exmaplE]
example_example.com [Example]
example_example.com [eXmaple]
example@example.com,example []

只要记录正确地格式化,它就可以很好。我认为您可以检查错误或信任您的数据。

最新更新