Output a header label in data field in miller

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Given file.csv:



a,b,c
1,2,3


How can mlr be made to output:



a,b,c
1,2,c


Using the label name of $c without knowing in advance that it's the letter "c"?




Note: correct answer must use mlr only.







share|improve this question






















  • do you want the last header column to be the last column value or all other records?
    – RomanPerekhrest
    Mar 14 at 15:35










  • @RomanPerekhrest, In this simplest possible case either way would be fine.
    – agc
    Mar 14 at 15:37










  • I hadn't come across miller - mlr - before - looks great, will have to spend some time playing with it and reading the docs. Thanks for the link.
    – cas
    Mar 15 at 6:14














up vote
1
down vote

favorite












Given file.csv:



a,b,c
1,2,3


How can mlr be made to output:



a,b,c
1,2,c


Using the label name of $c without knowing in advance that it's the letter "c"?




Note: correct answer must use mlr only.







share|improve this question






















  • do you want the last header column to be the last column value or all other records?
    – RomanPerekhrest
    Mar 14 at 15:35










  • @RomanPerekhrest, In this simplest possible case either way would be fine.
    – agc
    Mar 14 at 15:37










  • I hadn't come across miller - mlr - before - looks great, will have to spend some time playing with it and reading the docs. Thanks for the link.
    – cas
    Mar 15 at 6:14












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Given file.csv:



a,b,c
1,2,3


How can mlr be made to output:



a,b,c
1,2,c


Using the label name of $c without knowing in advance that it's the letter "c"?




Note: correct answer must use mlr only.







share|improve this question














Given file.csv:



a,b,c
1,2,3


How can mlr be made to output:



a,b,c
1,2,c


Using the label name of $c without knowing in advance that it's the letter "c"?




Note: correct answer must use mlr only.









share|improve this question













share|improve this question




share|improve this question








edited Mar 14 at 15:43

























asked Mar 14 at 15:31









agc

4,0391935




4,0391935











  • do you want the last header column to be the last column value or all other records?
    – RomanPerekhrest
    Mar 14 at 15:35










  • @RomanPerekhrest, In this simplest possible case either way would be fine.
    – agc
    Mar 14 at 15:37










  • I hadn't come across miller - mlr - before - looks great, will have to spend some time playing with it and reading the docs. Thanks for the link.
    – cas
    Mar 15 at 6:14
















  • do you want the last header column to be the last column value or all other records?
    – RomanPerekhrest
    Mar 14 at 15:35










  • @RomanPerekhrest, In this simplest possible case either way would be fine.
    – agc
    Mar 14 at 15:37










  • I hadn't come across miller - mlr - before - looks great, will have to spend some time playing with it and reading the docs. Thanks for the link.
    – cas
    Mar 15 at 6:14















do you want the last header column to be the last column value or all other records?
– RomanPerekhrest
Mar 14 at 15:35




do you want the last header column to be the last column value or all other records?
– RomanPerekhrest
Mar 14 at 15:35












@RomanPerekhrest, In this simplest possible case either way would be fine.
– agc
Mar 14 at 15:37




@RomanPerekhrest, In this simplest possible case either way would be fine.
– agc
Mar 14 at 15:37












I hadn't come across miller - mlr - before - looks great, will have to spend some time playing with it and reading the docs. Thanks for the link.
– cas
Mar 15 at 6:14




I hadn't come across miller - mlr - before - looks great, will have to spend some time playing with it and reading the docs. Thanks for the link.
– cas
Mar 15 at 6:14










1 Answer
1






active

oldest

votes

















up vote
1
down vote













Simply with awk:



awk 'BEGIN FS=OFS="," (NR == 1)? c=$NF : $NF=c 1' file.csv


Sample output:



a,b,c
1,2,c





share|improve this answer




















  • Thanks & sorry -- I'm at fault for not specifying that a mlr-only answer is required. (I'm trying to learn mlr, but it can be puzzling.) Q. revised to reflect language limitation. +1 because it works tho'...
    – agc
    Mar 14 at 15:47










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f430199%2foutput-a-header-label-in-data-field-in-miller%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Simply with awk:



awk 'BEGIN FS=OFS="," (NR == 1)? c=$NF : $NF=c 1' file.csv


Sample output:



a,b,c
1,2,c





share|improve this answer




















  • Thanks & sorry -- I'm at fault for not specifying that a mlr-only answer is required. (I'm trying to learn mlr, but it can be puzzling.) Q. revised to reflect language limitation. +1 because it works tho'...
    – agc
    Mar 14 at 15:47














up vote
1
down vote













Simply with awk:



awk 'BEGIN FS=OFS="," (NR == 1)? c=$NF : $NF=c 1' file.csv


Sample output:



a,b,c
1,2,c





share|improve this answer




















  • Thanks & sorry -- I'm at fault for not specifying that a mlr-only answer is required. (I'm trying to learn mlr, but it can be puzzling.) Q. revised to reflect language limitation. +1 because it works tho'...
    – agc
    Mar 14 at 15:47












up vote
1
down vote










up vote
1
down vote









Simply with awk:



awk 'BEGIN FS=OFS="," (NR == 1)? c=$NF : $NF=c 1' file.csv


Sample output:



a,b,c
1,2,c





share|improve this answer












Simply with awk:



awk 'BEGIN FS=OFS="," (NR == 1)? c=$NF : $NF=c 1' file.csv


Sample output:



a,b,c
1,2,c






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 14 at 15:40









RomanPerekhrest

22.4k12144




22.4k12144











  • Thanks & sorry -- I'm at fault for not specifying that a mlr-only answer is required. (I'm trying to learn mlr, but it can be puzzling.) Q. revised to reflect language limitation. +1 because it works tho'...
    – agc
    Mar 14 at 15:47
















  • Thanks & sorry -- I'm at fault for not specifying that a mlr-only answer is required. (I'm trying to learn mlr, but it can be puzzling.) Q. revised to reflect language limitation. +1 because it works tho'...
    – agc
    Mar 14 at 15:47















Thanks & sorry -- I'm at fault for not specifying that a mlr-only answer is required. (I'm trying to learn mlr, but it can be puzzling.) Q. revised to reflect language limitation. +1 because it works tho'...
– agc
Mar 14 at 15:47




Thanks & sorry -- I'm at fault for not specifying that a mlr-only answer is required. (I'm trying to learn mlr, but it can be puzzling.) Q. revised to reflect language limitation. +1 because it works tho'...
– agc
Mar 14 at 15:47












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f430199%2foutput-a-header-label-in-data-field-in-miller%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay