从文件中每一行的开头删除电子邮件字符串
Remove e-mail string from the beginning of each row in a file
我有一个格式如下的文件
email1@email.com some string with no set width
email2@email.com another string
email3@email.com yet another string!!
areallylongemail@email.com shortstring
我想要做的是 运行 一个 bash 命令,它将获取此文件并从每一行的开头删除 email+space 并将其输出到另一个文件。输出文件应该是
some string with no set width
another string
yet another string!!
shortstring
到目前为止我有 sed 's/^\S+\s//' test_input.txt > test_output.txt
但似乎没有用....
您可以使用 sed
:
sed 's/^[^[:blank:]@]\+@[^[:blank:]]\+[[:blank:]]*//' file > file.out
some string with no set width
another string
yet another string!!
shortstring
gnu sed 将与此一起工作:
sed 's/^[^\s@]\+@\S\+\s*//' file > file.out
如果只有一个 space 将电子邮件地址与该行的其余部分分开,那么您可以使用 cut
命令,告诉它使用 space 作为字段分隔符,并让它输出以第二个字段开头的所有字段。
cut -d' ' -f2- < file > file.out
我有一个格式如下的文件
email1@email.com some string with no set width
email2@email.com another string
email3@email.com yet another string!!
areallylongemail@email.com shortstring
我想要做的是 运行 一个 bash 命令,它将获取此文件并从每一行的开头删除 email+space 并将其输出到另一个文件。输出文件应该是
some string with no set width
another string
yet another string!!
shortstring
到目前为止我有 sed 's/^\S+\s//' test_input.txt > test_output.txt
但似乎没有用....
您可以使用 sed
:
sed 's/^[^[:blank:]@]\+@[^[:blank:]]\+[[:blank:]]*//' file > file.out
some string with no set width
another string
yet another string!!
shortstring
gnu sed 将与此一起工作:
sed 's/^[^\s@]\+@\S\+\s*//' file > file.out
如果只有一个 space 将电子邮件地址与该行的其余部分分开,那么您可以使用 cut
命令,告诉它使用 space 作为字段分隔符,并让它输出以第二个字段开头的所有字段。
cut -d' ' -f2- < file > file.out