Skip to content

Shifts the values of the record to the right by one #1144

Answered by johnkerl
aborruso asked this question in Q&A
Discussion options

You must be logged in to vote

@aborruso how about:

$ cat shifter.mlr
keys   = get_keys($*);
values = get_values($*);

newrec = {};
newrec[keys[1]] = "";
for (i = 1; i <= length(keys); i += 1) {
    newrec[keys[i+1]] = values[i];
}

$* = newrec;
$ mlr --implicit-csv-header --c2p --from input.csv cat
1 2 3 4
a 2 3 -
2 3 - -
b 4 5 -
$ mlr --implicit-csv-header --c2p --from input.csv put -f shifter.mlr
1 2 3 4
- a 2 3
- 2 3 -
- b 4 5

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@johnkerl
Comment options

@aborruso
Comment options

Answer selected by aborruso
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants