3

My file looks like:

19-04-05 08:45:22,643: INFO  [ByrioThread] [] kks.connectorLog: Very important information

I want to cut it using a two character delimiter ": ", but with field definition "field 2 and all next". This would be a cut command as:

cut -f2- -d': '

so the output would be:

INFO  [ByrioThread] [] kks.connectorLog: Very important information

however cut does not support multicharacter delimiter. Therefore answer given here How to use cut with multiple character delimiter? unix with awk does not work.

Any help appreciated!

pawel_j
  • 419
  • 4
  • 14
  • 1
    What is your expected output for this? – Inian Apr 08 '19 at 10:07
  • 3
    "cut does not support multicharacter delimiter" ... "Therefore answer ... with **awk** does not work." .. does not compute. Awk supports *regular expressions* as the field separator, it certainly supports multicharacter delimiters. What `cut` supports has nothing to do with Awk. – muru Apr 08 '19 at 10:14
  • 1
    If your numbers are zero padded, chances are that your information always start in the same column. In that case, don't try to cut on a field separator, just cut from a specific column: `cut -c24-` – Poshi Apr 08 '19 at 10:26

3 Answers3

2

This grep might work for you:

grep -Po ': \K.*' file

Or a pure bash solution using parameter expansion:

while IFS= read -r line; do
   printf '%s\n' "${line#*: }"
done < file
mickp
  • 1,679
  • 7
  • 23
1

You can use 'awk' with a multi-character delimiter.

awk -F": " 'BEGIN {OFS=FS} {$1=""; print $0}'  < input.txt | cut -c 3- 

As you require your delimiter to appear in the output you'll need to set your output field separator (OFS), otherwise you'll have your delimiter replaced with a space. This is done by BEGIN {OFS=FS}. We're then dropping the first field with $1="" and then printing out what remains, having dropped the unnecessary field separator (with cut)

Alternatively, we can remove the first field and the field separator and do this directly with:

awk -F": " 'BEGIN {OFS=FS} {sub($1 FS,"")}1' < input.txt

The removal is done by substituting the empty string for the first field and the field separator. The additional 1 then triggers the printing of the remaining text.

borrible
  • 17,120
  • 7
  • 53
  • 75
1

As the first part 19-04-05 08:45:22,643: is always fixed in size, why don't you go for:

$ echo '19-04-05 08:45:22,643: INFO  [ByrioThread] [] kks.connectorLog: Very important information' | sed -E 's/^.{23}//'
INFO  [ByrioThread] [] kks.connectorLog: Very important information

Or via grep

grep -oP '(?<=\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}: ).*'

or via awk

$ echo '19-04-05 08:45:22,643: INFO  [ByrioThread] [] kks.connectorLog: Very important information' | awk -F '\([0-9]{2}[:-] ?\)*,[0-9]{3}: ' '{print $2}'
INFO  [ByrioThread] [] kks.connectorLog: Very important information
Allan
  • 12,117
  • 3
  • 27
  • 51