I have "|" delimited file, with fields that represent:
firstname|secondname|Kernel|Version|Year
For example:
Linus|Torvald|VMLINUZ||1994
Jochen|Liedtke|L4|||
Apple||Darwin||2000
I want "\t" delimited results, with few conditionals.
If any column is empty, it'll substitute with "-", but it gets complex in few cases, where any of first or second name is empty. I don't want it to happen.
Simply, concatenate first & second name, but if any of these columns empty, don't replace with "-" otherwise this condition applies on other empty fields.
I wrote following awk script, but it replaces empty first or second name with "-" too.
BEGIN {
FS="|";
OFS="\t"
}
{ for (i = 1; i <= NF; ++i) sub(/^$/, "-", $i) }
{
print $5, $4, $2" "$1
}
It gives this output:
1994 - Torvald Linus
- - Liedtke Jochen
2000 - - Apple
so the last line should be
2000 - Apple
Final Output
1994 - Torvald Linus
- - Liedtke Jochen
2000 - Apple