Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
c0mmand
V2EX  ›  Linux

提取文本中特定字符前\后的数据,然后另存为新文本。

  •  
  •   c0mmand · Jun 8, 2016 · 3437 views
    This topic created in 3826 days ago, the information mentioned may be changed or developed.
    比如这样几行数据:
    [email protected]
    [email protected]
    [email protected]

    我想提取 @符号之前的数据另存为一新文本,----符号之后的数据另存为一新文本。

    初学 Linux ,正则表达式还没接触,只能求助了。




    没错,这是网易的裤子。
    7 replies  •  2016-06-15 16:52:35 +08:00
    jedyu
    jedyu
    Jun 8, 2016❤️1
    1
    split
    chunqiuyiyu
    chunqiuyiyu
    Jun 8, 2016❤️1
    2
    还是学学正则吧 就从这个例子开始 很简单的
    skydiver
    skydiver
    Jun 8, 2016❤️1
    3
    cat data.txt|cut -d'@' -f1
    cat data.txt|cut -d'-‘ -f5
    c0mmand
    c0mmand
    OP
    Jun 8, 2016
    4
    @skydiver 这命令怎样才能后台运行,不回显呢?现在会刷屏。
    c0mmand
    c0mmand
    OP
    Jun 8, 2016
    5
    @wuxiao2522 OK ,已经成功了。 cat data.txt|cut -d'@' -f1 >new.txt
    wweir
    wweir
    Jun 8, 2016
    6
    sed awk 大法好

    PS :正则+双重转义是我的宿敌,老错……
    yiyiwa
    yiyiwa
    Jun 15, 2016
    7
    awk -F'[@-]+' '{print $1>"1.txt";print $NF>"2.txt"}' file
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1961 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 14:42 · PVG 22:42 · LAX 06:42 · JFK 09:42
    ♥ Do have faith in what you're doing.