V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
wuxiao2522
V2EX  ›  Linux

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

  •  
  •   wuxiao2522 · 2016-06-08 13:51:44 +08:00 · 2633 次点击
    这是一个创建于 2885 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如这样几行数据:
    [email protected]
    [email protected]
    [email protected]

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

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




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

    PS :正则+双重转义是我的宿敌,老错……
    yiyiwa
        7
    yiyiwa  
       2016-06-15 16:52:35 +08:00
    awk -F'[@-]+' '{print $1>"1.txt";print $NF>"2.txt"}' file
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1093 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:00 · PVG 08:00 · LAX 17:00 · JFK 20:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.