Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Hack one-liner version. Perhaps more suitable for Code GolfCode Golf than this forum though. This generates split1, split2, split3 and so on, as filenames.

awk '{if($2>b+9999){a++;b=$2}print >"split" a}' file.txt

To have output files named split001, split002, split003, involves this extra sprintf:

awk '{if($2>b+9999){a++;b=$2}print >sprintf("split%03d",a)}' file.txt

To avoid the gawk slowdown issue identified by @Stéphane Chazelas, use perl:

perl -ne '(undef,$a)=split(/\s+/,$_);if($a>$b+9999){$c++;$b=$a}open(D,sprintf(">>ysplit%03d",$c));print D' <file.txt

Hack one-liner version. Perhaps more suitable for Code Golf than this forum though. This generates split1, split2, split3 and so on, as filenames.

awk '{if($2>b+9999){a++;b=$2}print >"split" a}' file.txt

To have output files named split001, split002, split003, involves this extra sprintf:

awk '{if($2>b+9999){a++;b=$2}print >sprintf("split%03d",a)}' file.txt

To avoid the gawk slowdown issue identified by @Stéphane Chazelas, use perl:

perl -ne '(undef,$a)=split(/\s+/,$_);if($a>$b+9999){$c++;$b=$a}open(D,sprintf(">>ysplit%03d",$c));print D' <file.txt

Hack one-liner version. Perhaps more suitable for Code Golf than this forum though. This generates split1, split2, split3 and so on, as filenames.

awk '{if($2>b+9999){a++;b=$2}print >"split" a}' file.txt

To have output files named split001, split002, split003, involves this extra sprintf:

awk '{if($2>b+9999){a++;b=$2}print >sprintf("split%03d",a)}' file.txt

To avoid the gawk slowdown issue identified by @Stéphane Chazelas, use perl:

perl -ne '(undef,$a)=split(/\s+/,$_);if($a>$b+9999){$c++;$b=$a}open(D,sprintf(">>ysplit%03d",$c));print D' <file.txt
perl
Source Link
steve
  • 22.3k
  • 5
  • 53
  • 79

Hack one-liner version. Perhaps more suitable for Code Golf than this forum though. This generates split1, split2, split3 and so on, as filenames.

awk '{if($2>b+9999){a++;b=$2}print >"split" a}' file.txt

To have output files named split001, split002, split003, involves this extra sprintf:

awk '{if($2>b+9999){a++;b=$2}print >sprintf("split%03d",a)}' file.txt

To avoid the gawk slowdown issue identified by @Stéphane Chazelas, use perl:

perl -ne '(undef,$a)=split(/\s+/,$_);if($a>$b+9999){$c++;$b=$a}open(D,sprintf(">>ysplit%03d",$c));print D' <file.txt

Hack one-liner version. Perhaps more suitable for Code Golf than this forum though. This generates split1, split2, split3 and so on, as filenames.

awk '{if($2>b+9999){a++;b=$2}print >"split" a}' file.txt

To have output files named split001, split002, split003, involves this extra sprintf:

awk '{if($2>b+9999){a++;b=$2}print >sprintf("split%03d",a)}' file.txt

Hack one-liner version. Perhaps more suitable for Code Golf than this forum though. This generates split1, split2, split3 and so on, as filenames.

awk '{if($2>b+9999){a++;b=$2}print >"split" a}' file.txt

To have output files named split001, split002, split003, involves this extra sprintf:

awk '{if($2>b+9999){a++;b=$2}print >sprintf("split%03d",a)}' file.txt

To avoid the gawk slowdown issue identified by @Stéphane Chazelas, use perl:

perl -ne '(undef,$a)=split(/\s+/,$_);if($a>$b+9999){$c++;$b=$a}open(D,sprintf(">>ysplit%03d",$c));print D' <file.txt
sprintf
Source Link
steve
  • 22.3k
  • 5
  • 53
  • 79

Hack one-liner version. Perhaps more suitable for Code Golf than this forum though. This generates split1, split2, split3 and so on, as filenames.

awk '{if($2>b+9999){a++;b=$2}print >"split" a}' file.txt

To have output files named split001, split002, split003, involves this extra sprintf:

awk '{if($2>b+9999){a++;b=$2}print >sprintf("split%03d",a)}' file.txt

Hack one-liner version. Perhaps more suitable for Code Golf than this forum though.

awk '{if($2>b+9999){a++;b=$2}print >"split" a}' file.txt

Hack one-liner version. Perhaps more suitable for Code Golf than this forum though. This generates split1, split2, split3 and so on, as filenames.

awk '{if($2>b+9999){a++;b=$2}print >"split" a}' file.txt

To have output files named split001, split002, split003, involves this extra sprintf:

awk '{if($2>b+9999){a++;b=$2}print >sprintf("split%03d",a)}' file.txt
Source Link
steve
  • 22.3k
  • 5
  • 53
  • 79
Loading