Skip to main content
fixed failure in printf when input was contain printf control characters
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 118

another awk alternative:

awk -F'[_-]' -v col=7 '{  while (col-->0) { printf "%s%s", $(NF-col), (col? "::" : ORS) };   }' infile 

adjust col=N with "number of N last columns" you want to print.


Answer to the revised question to:

So is there a away to generate print print $1,$3,$5.... programitcally so that OFS is automatically used

personally and also technically there is no reason to limit yourself to using OFS, but well if you want, here is how to do it:

awk -F'[_-]' -v col=7c=col=7 '{  while (col-->0) { printf "%s%s", $(NF-col), (col? XXX : ORS) };   }' XXX='::' infile 

but you know what is the behind OFS? replace all XXXs above with OFS; now remove XXX='::' and change XXX to just "::"; well so why stuck at using OFS then?

another awk alternative:

awk -F'[_-]' -v col=7 '{ while (col-->0) { printf $(NF-col) (col?"::":ORS) }; }' infile 

adjust col=N with "number of N last columns" you want to print.


Answer to the revised question to:

So is there a away to generate print print $1,$3,$5.... programitcally so that OFS is automatically used

personally and also technically there is no reason to limit yourself to using OFS, but well if you want, here is how to do it:

awk -F'[_-]' -v col=7 '{ while (col-->0) { printf $(NF-col) (col? XXX :ORS) }; }' XXX='::' infile 

but you know what is the behind OFS? replace all XXXs above with OFS; now remove XXX='::' and change XXX to just "::"; well so why stuck at using OFS then?

another awk alternative:

awk -F'[_-]' -v col=7 '{  while (col-->0) { printf "%s%s", $(NF-col), (col? "::" : ORS) };  }' infile 

adjust col=N with "number of N last columns" you want to print.


Answer to the revised question to:

So is there a away to generate print print $1,$3,$5.... programitcally so that OFS is automatically used

personally and also technically there is no reason to limit yourself to using OFS, but well if you want, here is how to do it:

awk -F'[_-]' -v c=col=7 '{  while (col-->0) { printf "%s%s", $(NF-col), (col? XXX : ORS) };  }' XXX='::' infile 

but you know what is the behind OFS? replace all XXXs above with OFS; now remove XXX='::' and change XXX to just "::"; well so why stuck at using OFS then?

added 567 characters in body
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 118

another awk alternative:

awk -F'[_-]' -v col=7 '{ while (col-->0) { printf $(NF-col) (col?"::":ORS) }; }' infile 

adjust col=N with "number of N last columns" you want to print.


Answer to the revised question to:

So is there a away to generate print print $1,$3,$5.... programitcally so that OFS is automatically used

personally and also technically there is no reason to limit yourself to using OFS, but well if you want, here is how to do it:

awk -F'[_-]' -v col=7 '{ while (col-->0) { printf $(NF-col) (col? XXX :ORS) }; }' XXX='::' infile 

but you know what is the behind OFS? replace all XXXs above with OFS; now remove XXX='::' and change XXX to just "::"; well so why stuck at using OFS then?

another awk alternative:

awk -F'[_-]' -v col=7 '{ while (col-->0) { printf $(NF-col) (col?"::":ORS) }; }' infile 

adjust col=N with "number of N last columns" you want to print.

another awk alternative:

awk -F'[_-]' -v col=7 '{ while (col-->0) { printf $(NF-col) (col?"::":ORS) }; }' infile 

adjust col=N with "number of N last columns" you want to print.


Answer to the revised question to:

So is there a away to generate print print $1,$3,$5.... programitcally so that OFS is automatically used

personally and also technically there is no reason to limit yourself to using OFS, but well if you want, here is how to do it:

awk -F'[_-]' -v col=7 '{ while (col-->0) { printf $(NF-col) (col? XXX :ORS) }; }' XXX='::' infile 

but you know what is the behind OFS? replace all XXXs above with OFS; now remove XXX='::' and change XXX to just "::"; well so why stuck at using OFS then?

Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 118

another awk alternative:

awk -F'[_-]' -v col=7 '{ while (col-->0) { printf $(NF-col) (col?"::":ORS) }; }' infile 

adjust col=N with "number of N last columns" you want to print.