【问题标题】:Using csplit in Bash script with Form Feed Regex在带有 Form Feed Regex 的 Bash 脚本中使用 csplit
【发布时间】:2016-08-23 17:58:24
【问题描述】:

我有一个包含换页的打印输出文件 (uncomp.txt)。我正在尝试根据 \f 正则表达式匹配将单个文档拆分为多个文档,并输出带有纪元时间的文件。

我试过了:

$ csplit --prefix=$(date +%s) -s  /tmp/uncomp.txt "/%\f%/+1" "{*}"

还有这个:

$ csplit --prefix=$(date +%s) -s  /tmp/uncomp.txt "/\f/+1" "{*}"

甚至这个:

$ csplit -s  --prefix=$(date +%s) /tmp/uncomp.txt /\f/ {*}

但每次我都得到一个文件。它显然没有拿起 \f 正则表达式......我做错了什么?

【问题讨论】:

    标签: regex bash csplit


    【解决方案1】:

    就这样试了,使用the standalone bash shell for windows

    csplit -z --prefix=Stored dumpstored.sql /^L/ "{*}"
    

    我通过按 CTRL+L 获得了^L。它对我有用。

    【讨论】:

      【解决方案2】:

      bash 解决方案

      csplit 似乎在其正则表达式中需要文字换页符。实现这一目标的一种方法是使用 bash 的 $'...' 构造:

      csplit --prefix=$(date +%s) -s  uncomp.txt $'/\f/+1' "{*}"
      

      POSIX 解决方案

      如果没有 bash,可以使用printf:

      csplit --prefix=$(date +%s) -s  uncomp.txt "/$(printf "\f")/+1" "{*}"
      

      或者,等效地:

      csplit --prefix=$(date +%s) -s  uncomp.txt "$(printf "/\f/+1")" "{*}"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-10-17
        • 1970-01-01
        • 2019-01-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多