删除每一行“/”之前的所有内容

use*_*022 3 text-processing regular-expression

我试图删除出现/在每一行之前的某些文本。

我有类似的东西:

testing.db.com/7fad416d-f2b3-4259-b98d-2449957a3123
testing.db.com/8a8589bf-49e3-4cd7-af15-6753067355c6
Run Code Online (Sandbox Code Playgroud)

我只想结束:

7fad416d-f2b3-4259-b98d-2449957a3123
8a8589bf-49e3-4cd7-af15-6753067355c6 
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我使用正则表达式吗?我发现的所有内容都在删除之后 /,而不是之前

hee*_*ayl 5

使用cut

$ cut -sd'/' -f2 file.txt   ##This will print only the lines containing /
7fad416d-f2b3-4259-b98d-2449957a3123
8a8589bf-49e3-4cd7-af15-6753067355c6
Run Code Online (Sandbox Code Playgroud)

以下建议假设/在一行中只出现一次:

使用grep

$ grep -o '[^/]*$' file.txt  ##This will print the lines not having / too
7fad416d-f2b3-4259-b98d-2449957a3123
8a8589bf-49e3-4cd7-af15-6753067355c6
Run Code Online (Sandbox Code Playgroud)

如果你有/所有的行,你也可以使用这些:

使用bash参数扩展:

$ cut -sd'/' -f2 file.txt   ##This will print only the lines containing /
7fad416d-f2b3-4259-b98d-2449957a3123
8a8589bf-49e3-4cd7-af15-6753067355c6
Run Code Online (Sandbox Code Playgroud)

或者python

$ grep -o '[^/]*$' file.txt  ##This will print the lines not having / too
7fad416d-f2b3-4259-b98d-2449957a3123
8a8589bf-49e3-4cd7-af15-6753067355c6
Run Code Online (Sandbox Code Playgroud)

请注意,就您的示例而言,上述所有建议都是有效的。