Giter VIP home page Giter VIP logo

columpaget / columscut Goto Github PK

View Code? Open in Web Editor NEW
7.0 5.0 1.0 70 KB

A unix cut command that supports: multiple delimiters, outputing fields in any specified order, outputing a different delimiter to the ones in the input, treating runs of delimiters as a single delimiter, and honoring quoting within the target document.

License: Other

Makefile 0.99% C 75.88% Shell 7.89% Roff 15.24%
c coreutils cut

columscut's People

Contributors

columpaget avatar darkshram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

shekkbuilder

columscut's Issues

Extra Comma at End?

I wouldn't have expected this comma at the end of the line when the range goes beyond the number of fields:

Helios:~ larry$ echo -e 'one one,one two,one three,one four,one five,one six,one seven,one eight\ntwo one,two two,two three,two four,two five,two six,two seven,two eight,two nine' | tee /dev/tty | ccut -d , -f 1-9
one one,one two,one three,one four,one five,one six,one seven,one eight
two one,two two,two three,two four,two five,two six,two seven,two eight,two nine
one one,one two,one three,one four,one five,one six,one seven,one eight,
two one,two two,two three,two four,two five,two six,two seven,two eight,two nine

Feature Request: output array (and bug - extra blank line?)

You're going to start disliking me :(

I numbered the output to make it more obvious:

1 Helios:~ larry$ echo -e 'one,"two a,two b",three,four\nfive,six,seven,eight' | ccut -d , -Q -f 2,3    
2 two a,two b,three
3 six,seven
4 Helios:~ larry$ echo -e 'one,"two a,two b",three,four\nfive,six,seven,eight' | ccut -d , -Q -f 2,3 -V a,b
5 a='two a,two b'; b='three'; 
6 

(Blank line generated for second line of output when variable generation is requested.)

By extention, it seems like it would be logical for variable generation to generate array definition statements for multiple rows; something like:

Helios:~ larry$ echo -e 'one,"two a,two b",three,four\nfive,six,seven,eight' | ccut -d , -Q -f 2,3 -V a,b
a[0]='two a,two b'; b[0]='three'; 
a[1]='six'; b[1]='seven'

Bashslash for a delimiter doesn't work?

Helios:ColumsCut larry$ echo one\\two\\three\\four | ccut -d \\ -f 4,1
one\two\three\four
Helios:ColumsCut larry$ echo one\\two\\three\\four | ccut -d '\' -f 4,1
one\two\three\four

I note, however, that this works:

Helios:ColumsCut larry$ echo one\\two\\three\\four | ccut -d '\\' -f 4,1
four\one

This is how GNU coreutils cut works:

Helios:ColumsCut larry$ echo 'one\two\three\four' | cut -d \\ -f 4,1
one\four
Helios:ColumsCut larry$ echo 'one\two\three\four' | cut -d '\' -f 4,1
one\four
Helios:ColumsCut larry$ echo 'one\two\three\four' | cut -d '\\' -f 4,1
gcut: the delimiter must be a single character
Try 'gcut --help' for more information.

“(null)” in output

I already mentioned this in another comment, but wanted to make it a separate issue, plus this is an interesting (to me) use of ccut - make a rocket ship, with a count-down

larryp-mbp:ColumsCut larry$ for ((i=1; i<=10; i++)); do for ((j=1; j<=i; j++)); do echo -n $j\ ; done; echo; done | ./ccut -d ' ' -f 8-1 | cat -v
(null)(null)(null)(null)(null)(null) 1
      2 1
     3 2 1
    4 3 2 1
   5 4 3 2 1
  6 5 4 3 2 1
 7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
8 7 6 5 4 3 2 1

Should probably come out

       1
      2 1
     3 2 1
    4 3 2 1
   5 4 3 2 1
  6 5 4 3 2 1
 7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
8 7 6 5 4 3 2 1

Now that reverse ranges are an option, delimiters get misplaced

Looks like the delimiter gets removed from the end of range and gets added to the beginning:

Helios:~ larry$ echo -e 'one one,one two,one three,one four,one five,one six,one seven,one eight\ntwo one,two two,two three,two four,two five,two six,two seven,two eight,two nine' | tee /dev/tty | ccut -d , -f 5-3,8-6
one one,one two,one three,one four,one five,one six,one seven,one eight
two one,two two,two three,two four,two five,two six,two seven,two eight,two nine
,one five,one four,one threeone eight,one seven,one six
,two five,two four,two threetwo eight,two seven,two six

Off-by-one error caused by backslash in delimstr?

E.g., works as expected but with unprotected backslash:

Helios:ColumsCut larry$ echo 'one\/two\/three\/four' | ccut -D '\/' -f 1,4
one\/four
Helios:ColumsCut larry$ echo 'one\/two\/three\/four' | ccut -D '\/' -f 1-4
one\/two\/three\/four

Protected backslash truncates output:

Helios:ColumsCut larry$ echo 'one\/two\/three\/four' | ccut -D '\\/' -f 1,4
one\/fou
Helios:ColumsCut larry$ echo 'one\/two\/three\/four' | ccut -D '\\/' -f 1-4
one\/two\/three\/fou

The -s / --only-delimited option seems to not work as expected

input: seq -f '%.f to be output' 0 5 20|ccut -s -d 5 -f 2
output:

 
to be output
<�V
 to be output
<�V

input: seq -f '%.f to be output' 0 5 20|ccut --only-delimited -d 5 -f 2
output:


 to be output
FU
 to be output
FU

input: seq -f '%.f to be output' 0 5 20|ccut -d 5 -s -f 2
output:


 to be output
2MU
 to be output
MU

input: seq -f '%.f to be output' 0 5 20|ccut -d 5 -f 2 -s
output:


 to be output
h�V
 to be output
h�V

Expected output in all cases is

 to be output
 to be output

I get the expected output with cut from GNU Coreutils:
seq -f '%.f to be output' 0 5 20|cut -sd5 -f2
or with scut from Schily Tools:
seq -f '%.f to be output' 0 5 20|scut d=5 f=2 -s

OS: CentOS 8. I'm attaching the Mock build log. My spec file is here.

build.log

Should argument parsing ignore spacing?

Helios:ColumsCut larry$ echo one,two,three,four | ccut -d, -f1
Helios:ColumsCut larry$ echo one,two,three,four | ccut -d, -f 1
ERROR: Failed to open [1]
Helios:ColumsCut larry$ echo one,two,three,four | ccut -d , -f1
ERROR: Argument missing after '-f1'
Helios:ColumsCut larry$ echo one,two,three,four | cut -d, -f1  
one
Helios:ColumsCut larry$ echo one,two,three,four | cut -d , -f1
one
Helios:ColumsCut larry$ echo one,two,three,four | cut -d, -f 1
one

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.