Reputation: 1936
I have data that looks like this (naturally I have GBs of it)
[[1,2,3],[4,5,6],[5,6,7],[8,9,10]]
and it is all output on one file as such.
I was wondering if it would be possible using regular expressions, awk
, sed
, grep
, or pure bash to pipe the output so I get it to appear as such
1,2,3
4,5,6
5,6,7
8,9,10
Upvotes: 0
Views: 20
Reputation: 8412
You can use awk
echo "[[1,2,3],[4,5,6],[5,6,7],[8,9,10]]"|awk -v OFS="\n" '{gsub(/(\],\[|\]\]|\[\[)/," ");for(i=1;i<=NF;++i){print $i}}'
results
1,2,3
4,5,6
5,6,7
8,9,10
Upvotes: 1
Reputation: 44023
With sed:
echo '[[1,2,3],[4,5,6],[5,6,7],[8,9,10]]' | sed 's/\],\[/\n/g;s/\[\|\]//g'
This consists of the two commands
s/\],\[/\n/g # replace all instances of ],[ with newlines
s/\[\|\]//g # remove remaining [ and ] (at the beginning and end)
Upvotes: 2