Examples

  1. Assume that the sample.txt file contains the following:

    # This is a comment line
    
            f1 = a b c    # First line of tokens
            x y z         # Second line of tokens
            aaa bbbb  "cccc   ddddd"  # Last line of tokens
    

    Run the following command:

            txtcut -d: sample.txt
    

    The txtcut command writes the following to stdout:

            f1:=:a:b:c
            x:y:z
            aaa:bbbb:cccc   ddddd
    

  2. Using the same sample.txt file from the previous example, we'll cut the third field from each line of the file by running the following command:

            txtcut sample.txt | cut -f3
    

    The following is written to stdout:

            a
            z
            cccc   ddddd
    

  3. Again, using the same sample.txt file from the previous examples, we'll cut the third field from each line of the file. But this time we'll pipe the file into txtcut's standard input and we'll use a colon for the delimiter:

            cat sample.txt | txtcut -d: | cut -f3 -d:
    

    Again, the following is written to stdout:

            a
            z
            cccc   ddddd
    

  4. Using the same sample.txt file in example 1, we will add the filename, the line number within the file where each line of tokens was found, and the number of tokens in the line. The following shows a set of commands and the output from each of them:

    1. txtcut -d: sample.txt

      f1:=:a:b:c
      x:y:z
      aaa:bbbb:cccc   ddddd
      

    2. txtcut -d: -n sample.txt

      sample.txt:f1:=:a:b:c
      sample.txt:x:y:z
      sample.txt:aaa:bbbb:cccc   ddddd
      

    3. txtcut -d: -l sample.txt

      3:f1:=:a:b:c
      4:x:y:z
      5:aaa:bbbb:cccc   ddddd
      

    4. txtcut -d: -n -l sample.txt

      sample.txt:3:f1:=:a:b:c
      sample.txt:4:x:y:z
      sample.txt:5:aaa:bbbb:cccc   ddddd
      

    5. txtcut -d: -n -l -c sample.txt

      sample.txt:3:5:f1:=:a:b:c
      sample.txt:4:3:x:y:z
      sample.txt:5:3:aaa:bbbb:cccc   ddddd