AMPSYS
AMPSYS

Reputation: 23

Using csplit in Bash script with Form Feed Regex

I have a print output file (uncomp.txt) that has form feeds in it. I'm trying to split the single document into multiple documents based on the \f regex match, and outputting files with the epoch time.

I've tried this:

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

as well as this:

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

and even this:

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

But each time I end up with a single file. It's apparently not picking up the \f regex... What am I doing wrong?

Upvotes: 0

Views: 629

Answers (3)

LenW
LenW

Reputation: 1694

I don't believe you want the "+1" after the regex. For me this moves the first line of each page to the previous page. (BTW, for the explanation of the $'...' construct, search for the string 'ANSI C' in the bash manpage.)

Upvotes: 0

iw1dov
iw1dov

Reputation: 1

Just tried like this, using the standalone bash shell for windows

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

where I obtained ^L by pressing CTRL+L. It worked for me.

Upvotes: 0

John1024
John1024

Reputation: 113924

bash solution

It appears that csplit requires a literal formfeed in its regex. One way to achieve that is to use bash's $'...' construct:

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

POSIX solution

If you don't have bash, you can use printf:

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

Or, equivalently:

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

Upvotes: 1

Related Questions