Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completely unexpted output of put, then cut, then label #1564

Closed
ghmon opened this issue May 15, 2024 · 3 comments
Closed

Completely unexpted output of put, then cut, then label #1564

ghmon opened this issue May 15, 2024 · 3 comments

Comments

@ghmon
Copy link

ghmon commented May 15, 2024

[miller 6.12.0]

After searching an error in my statement for two hours, then even asked chatgpt-4 which came out with exactly the same solution i used before i consider this a bug or a profound misunderstanding of miller.

Task: read csv file, add new column, cut part of columns and rearrange, new label (header).

with awk/sed:
echo latitude,longitude,elevation,name; awk -v FS="," '{ print $5 "," $4 ",0," $1}' "$1" | sed 1d

Input (first two data lines only):

Sendername,Block,Blockmittenfrequenz,Geo Länge WGS84,Geo Breite WGS84,Land geographisch,T-DAB-Modus,ERP-MAX horizontal,ERP-MAX vertikal,Polarisation,Antennencharakteristik D/N,HEFF_MAX,Land administrativ,Datum der Veröffentlichung,Datum der Änderung
Aachen,9A,202.928,6.24417,50.7714,D,null,null,30.0,V,D,358,D,28.04.2024,null
Aachen,9A,202.928,6.24361,50.7836,D,null,null,37.5,V,D,355,D,28.04.2024,null

Command (in a bash script):

mlr --csv --from "$1" \
put '$elevation = "0"' \
then cut -f '{Geo Breite WGS84},{Geo Länge WGS84},elevation,Sendername' \
then label latitude,longitude,elevation,name

Output (first two data lines only):

latitude,longitude
Aachen,0
Aachen,0

Expected output:

latitude,longitude,elevation,name
50.7714,6.24417,0,Aachen
50.7836,6.24361,0,Aachen

@ghmon ghmon changed the title Output not understandable Completely unexpted output of put, then cut, then label May 15, 2024
@aborruso
Copy link
Contributor

aborruso commented May 15, 2024

Hi @ghmon ,
in cut you should use " for field names with spaces, and you must force the order of the fields to be maintained (-o), otherwise the starting order applies and then you must apply the "label" command accordingly.

mlr --csv --from input.csv \
put '$elevation = "0"' \
then cut -o -f "Geo Breite WGS84","Geo Länge WGS84",elevation,Sendername \
then label latitude,longitude,elevation,name

@ghmon
Copy link
Author

ghmon commented May 15, 2024

mlr --csv --from input.csv [...]

Thank you!!! That works! I close the issue. Your usage of "-o Retain fields in the order specified" was also crucial.

@aborruso
Copy link
Contributor

ok @ghmon , if it's ok, please close the issue

@ghmon ghmon closed this as completed May 15, 2024
@ghmon ghmon reopened this May 15, 2024
@ghmon ghmon closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants