Column formatting

  • Anonymous - 2011-09-26

    Forgive me if this was already answered before, but is there a place somewhere in the help (or elsewhere) where I could find an explanation for what strings like "$col3$col2" mean?

    There are many examples that are using "col", and other characters in the "SFK filter" help section, but I have no clue what they mean.

    Thank you

  • stahlworks

    stahlworks - 2011-09-26

    The "sfk filter" help text is very long, if you look carefully you will find

    -sep[arate] "; " -form "$col1 mytext $[-0n.nq]col2 ..."
       break every line into columns separated by any character listed after -sep,
       then reformat the text according to a user-defined mask. when leaving out -sep,
       the whole line is packed into column 1. if -spat was specified, then -form
       also supports slash patterns like \t.

    So $col1, $col2 … means columns of text after a line was split by some character. Example:


    sfk echo "foo:bar"  +filter -separate ":" -form "$col2 - $col1"

    will print "bar - foo", i.e. the text was split in columns, and the columns reordered.

  • Anonymous - 2011-09-26

    Thanks. That's exactly my problem though.
    When I look at this: "$col2" I have no idea what the "-", "0", "n", and "q" mean…

    You're saying that this is in the help as well?

  • stahlworks

    stahlworks - 2011-09-27
    -form "$40col1 $-3.5col2 $05qline $(10.10qcount+1000)"
       reformat column 1 as right-ordered with at least 40 chars, column 2 left-
       ordered with at least 3 and a maximum of 5 chars, then add the input line
       number, "q"uoted, right justified with 5 digits, prefixed by zeros,
       then the output line number plus 1000 within quotes. NOTE: some examples
       may not work in an sfk script, see section "common errors" below.
       adding values so far only works with (q)line and (q)count.

    If you just want to split a line into columns of text, then print those columns,
    simply ignore all "-", "0" and "q" stuff as you don't need it.

    But if you want to define
    - how many characters should be printed per column
    - if a column should be printed as "text    " (left justified)
      or "     text" (right justified)
    - if numbers should be prefixed by zeros
    - if the columns should be placed in quotes ""

    then things are getting more complex. C programmers will instantly understand
    the above syntax, as it is similar to a function called "printf".

    Here are some more examples:

          -form "$col1"            print first column as is
          -form "$qcol1"           print first column with quotes "" around
          -form "$20col1"          extend first column to 20 characters of text, prefixed by blank characters
          -form "$020col1"         extend first column to 20 characters of text, prefixed by 0 digits
          -form "$.10col1"         limit / truncate first column to 10 characters
          -form "$col1 $count"     after text of first column, add a counter like 1
          -form "$col1 $03count"   after text of first column, add a three digit counter like 001
          -form "$col1 $03qcount"  add a three digit counter with quotes around like "001"

    I see I have to extend the help text by further examples.

  • Anonymous - 2011-09-27

    Thank you!
    Once you said it's based on Printf, I just looked it up on Wikipedia, and now it makes sense.
    Providing a "you can find more help by reading about the printf function online", may be a good idea for your help file.

    Thank you!


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks