Git Product home page Git Product logo

concat's Introduction

concat

Commandline program to concatenate file lines. Supports a separator string, removing empty lines, removing leading whitespaces, grouping and can be used in pipes.

Background

When one googles how to join lines in e.g. Bash, then you might find solutions like shown here. One of these solutions is a Posix commandline tool called paste, which already has a misleading name and uses in the short description also the word "merge", which again is misleading in my opinion. So it was time to create something that makes more sense.

Building

make

Usage

concat [-vhlwne] [-s <sep>] [-g <num>] [-S <sep>] [file]

You can't pass a file when text is piped into concat.

Options

-s <sep>  optional separator string
-g <num>  add group separator string after <num> of lines
-S <sep>  optional group separator string (default is newline)
-e        interpret some few escape sequences (\\,\t,\n)
-l        remove empty lines
-w        remove leading whitespaces
-n        do not output the trailing newline
-v        print version info
-h        print help text

Examples

Simple Concatenation

$ cat file
a
b
c
$ concat file
abc
$ echo -e "a\nb\nc" | concat
abc

Concatenation With Separator With -s

$ cat file
a
b
c
$ concat -s ',' file
a,b,c
$ cat file | tr '\n' ','
a,b,c,
$ concat -e -s '\t' file
a    b    c
$ concat -s ' - ' file
a - b - c

Notice how tr would replace also the last newline with a comma, which sometimes is not what you want, e.g. when in CSV files the last comma would create a new empty column.

Concatenation And Removing Empty Lines With -l

$ cat file
a

b

c
$ concat -s ';' file
a;;b;;c
$ concat -s ';' -l file
a;b;c

Concatenation And Removing Leading Whitespaces With -w

$ cat file
a
  b
    c
$ concat -s ':' file
a:  b:    c
$ concat -s ':' -w file
a:b:c

Concatenate A Given Number Of Lines With -g and -S

$ cat file
a
b
c
a
b
c
$ concat file
abcabc
$ concat -g 3 file
abc
abc
$ concat -e -g 3 -S '\n---\n' file
abc
---
abc

concat's People

Contributors

marcotrosi avatar w3bdev1 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

w3bdev1

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.