Tag Info

New answers tagged

0

The application XMLStarlet appears to be available on OSX via brew, so you should be able to install it like so: $ brew install xmlstarlet Once it's installed, you use it via the command line via the command xmlstarlet. Usage $ xmlstarlet XMLStarlet Toolkit: Command line utilities for XML Usage: xmlstarlet [<options>] <command> ...


0

Though I had to remove the last comma in your example input to make it work because jq was complaining about expecting another array element, this: INPUT | jq -r '[.[][].displayName], [.[][].value]| join(", ")' ...got me... First Name, Last Name, Position, Company Name, Country VALUE, VALUE, VALUE, VALUE, VALUE How it works in a nutshell: I traversed ...


0

Since you tagged this python and assuming name of json file is x.json import os, json with open('x.json') as f: x = json.load(f) print '{}{}{}'.format(', '.join(y['displayName'] for y in x['data']), os.linesep, ', '.join(y['value'] for y in x['data'])) First Name, Last Name, Position, Company Name, Country VALUE, VALUE, VALUE, VALUE, ...


1

I've found jq hard to wrap my head around. Here's some Ruby: ruby -rjson -rcsv -e ' data = JSON.parse(File.read "file.json") data["data"].collect {|item| [item["displayName"], item["value"]]} .transpose .each {|row| puts row.to_csv} ' First Name,Last Name,Position,Company Name,Country VALUE,VALUE,VALUE,VALUE,VALUE The ...


3

Given just this file, you can do something like: <testfile jq -r '.data | map(.displayName), map(.value) | join(", ")' The . operator selects a field from an object/hash. Thus, we start with .data, which returns the array with the data in it. We then map over the array twice, first selecting the displayName, then selecting the value, giving us two ...


2

First of all, less is just a pager, it is a tool that lets you read files. What you're doing is exactly the same as copying input_file to out_put.csv (cp input_file out_put.csv). You're not changing the content in any way. So, to read it as a spreadsheet using, for example libreoffice, you would need to open your spreadsheet application, then open your ...


2

Assuming you want to remove any cases of : followed by numbers from the 4th column (you say the 6th in your question but it's the 4th in your example), you can use one of these: awk awk -F';' -v OFS=";" '{sub(/\.[0-9]*$/,"",$6);}1;' file.csv > new.csv Perl (this changes the actual file and keeps the original as file.csv.bak) perl -i.bak -F';' -ane ...


1

To use python from the command line, you can check out pythonpy (https://github.com/Russell91/pythonpy): $ echo $'a,b,c\nd,e,f' | py '[x[1] for x in csv.reader(sys.stdin)'] b e



Top 50 recent answers are included