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

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

  •  
  •   c0mmand · Jun 8, 2016 · 3251 views
    This topic created in 3703 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
        1
    jedyu  
       Jun 8, 2016   ❤️ 1
    split
    chunqiuyiyu
        2
    chunqiuyiyu  
       Jun 8, 2016   ❤️ 1
    还是学学正则吧 就从这个例子开始 很简单的
    skydiver
        3
    skydiver  
       Jun 8, 2016   ❤️ 1
    cat data.txt|cut -d'@' -f1
    cat data.txt|cut -d'-‘ -f5
    c0mmand
        4
    c0mmand  
    OP
       Jun 8, 2016
    @skydiver 这命令怎样才能后台运行,不回显呢?现在会刷屏。
    c0mmand
        5
    c0mmand  
    OP
       Jun 8, 2016
    @wuxiao2522 OK ,已经成功了。 cat data.txt|cut -d'@' -f1 >new.txt
    wweir
        6
    wweir  
       Jun 8, 2016
    sed awk 大法好

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