I have this input:
XX3083136|bla-bla texthere texttt|asfdasfd@safdsadf.com|SADFdsafsafd|ASDfasfdsafd|DSFSAFD|dsafasfd|sadfsad|
XX3083372|bla-bla-bla this is a text bla-bla|asdfsfda@lsadfasfdda.com|SDFsafas|SADFsa|DFSsdf|asdasdf|sadfdsafsaf|asdfsadf|
and I need this output:
XX3083136|bla-bla texthere textt|asfdasfd@safdsadf.com |SADFdsafsafd|ASDfasfdsafd|DSFSAFD|dsafasfd|sadfsad|
XX3083372|bla-bla-bla this is a te|asdfsfda@lsadfasfdda.com |SDFsafas|SADFsa|DFSsdf|asdasdf|sadfdsafsaf|asdfsadf|
So the difference is that I need to control the max text length between the "|". If it's shorter then given line lenght then " " need to be putted.
In this example the second row is limited to max 24 chars and the third row has to be at least 30 chars. Different rows will need different max/min limits..
How can I do this in bash?
Best Answer
To supplement a little:
Basic format for
printf
in text is:When one get long patterns it can become a bit messy to keep track on where and which etc. One way to make it a bit easier could be something like this:
Or. e.g.:
If it is only line parsing then awk is an good alternative. e.g.:
Or: