How are you doing. I have a file that has 5 fields separated by pipes
Example:
0987123443|InfoBasica||Derivación Proceso|8899776673|Cliente 10001144795 no existe.|
In which the last field, in this example would be "Client 10001144795 does not exist." is the error message. The errors are not always the same and new errors may appear. What you would need is that every time a new error is found, that last field is added to a file. The file that contains errors does not always have the same number of lines, so one day 10 may appear, other times 900, and so on.
More in detail the file could come like this:
0987123443|InfoBasica||Derivación Proceso|8899776673|Cliente 10001144795 no existe.|
3246656545|InfoBasica||Derivación Proceso|6587678778|Cliente 12341241243 duplicado.|
3457878784|InfoBasica||Derivación Proceso|5486787867|Cliente 45675467456 duplicado.|
2345326654|InfoBasica||Derivación Proceso|0987090909|Cliente 34543254545 no existe.|
How can I do it in Linux?
From what I see, there are two keywords that I'll take to try to help you: delimiter "|", and "last" field.
For that we can use
awk
. For example, let's use this to read all your records separated by "|":Resulting in:
I used
$(NF-1)
because, due to the way your lines are written, you don't ask for the last character since the last character would be empty, but you ask for the penultimate. NF is a variableawk
that contains the number of fields.Already after doing this, you can redirect the output of that command to a file of your choice: