Skip to content

Instantly share code, notes, and snippets.

@dalethedeveloper
Last active August 29, 2015 14:11
Show Gist options
  • Save dalethedeveloper/cc1f482f5ebdf07ccf26 to your computer and use it in GitHub Desktop.
Save dalethedeveloper/cc1f482f5ebdf07ccf26 to your computer and use it in GitHub Desktop.

Revisions

  1. dalethedeveloper revised this gist Dec 13, 2014. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions gistfile1.awk
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,11 @@
    # Assumes a tab delimited flat file and the first field being a numeric key
    BEGIN{
    FS=OFS="\t";
    p="";
    BEGIN {
    FS = OFS = "\t";
    p = "";
    }
    # Strategy is to readline, check for key in first field, store to print
    # on next readline if the next record has a key in first field, otherwise
    # append our fragmented line to the stored line
    {
    sub(/\r/,""); # also scrub those pesky carriage returns
    if( $1 ~ /^[0-9]+$/ ) {
    @@ -16,3 +19,6 @@ BEGIN{
    p = p " " $0;
    }
    }
    END {
    print p
    }
  2. dalethedeveloper created this gist Dec 13, 2014.
    18 changes: 18 additions & 0 deletions gistfile1.awk
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # Assumes a tab delimited flat file and the first field being a numeric key
    BEGIN{
    FS=OFS="\t";
    p="";
    }
    {
    sub(/\r/,""); # also scrub those pesky carriage returns
    if( $1 ~ /^[0-9]+$/ ) {
    if( p != "" ) {
    sub(/^\s+/,"",p);
    print p;
    p = "";
    }
    p = $0
    } else {
    p = p " " $0;
    }
    }