Search code examples
shelltextlinepastecut

Shell programming: how to cut from each line's head to paste to line end?


E.g, I've got a build.log file, each line is like this:

[2017-02-13 16:37:41.123456] [warning]  [1743]  [mysource/impl.cpp:25] Syntax warning ...

I need to convert its format to be like this:

[warning]  [1743]  [mysource/impl.cpp:25] Syntax warning ...[2017-02-13 16:37:41.123456]

So my question is, how to cut the leading timestamp within the first [] and paste to line end?

How to do it wish bash/sed/awk(anyway)? Thanks.


Solution

  • Try something like:

    echo "[2017-02-13 16:37:41.123456] [warning]  [1743]  [mysource/impl.cpp:25] Syntax warning " | awk -F" " '{for(i=3;i<=NF;++i)printf ("%s ", $i); printf("%s %s\n", $1, $2)}'