[SOLVED] Script command for make a table
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
-
- Level 1
- Posts: 45
- Joined: Fri Jul 10, 2020 7:09 pm
[SOLVED] Script command for make a table
Good morning.
I need to format a kind of economic data.
I build some bin bash, then I recive csv "dirty" data and I like to sort this data in columns, but I can't find the tool.
I send some image, I like to build something like this: (forgiveme but my english is too horrible).
Thank you very much.
Matias Mittelbach
I need to format a kind of economic data.
I build some bin bash, then I recive csv "dirty" data and I like to sort this data in columns, but I can't find the tool.
I send some image, I like to build something like this: (forgiveme but my english is too horrible).
Thank you very much.
Matias Mittelbach
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 3 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Scritp command for make a table
For numeric sort per column 1 and ',' delimiter
It's hard to say more as there is no sample data and picture is too small
Code: Select all
sort -k1 -n -t ',' filename
sort -k1 -n -t ',' filename >filename_sorted
Code: Select all
man sort
-=t42=-
-
- Level 1
- Posts: 45
- Joined: Fri Jul 10, 2020 7:09 pm
Re: Script command for make a table
Thank you very much.
I will prove
This is an image of the csv data.
Thanks
Matias
I will prove
This is an image of the csv data.
Thanks
Matias
Re: Script command for make a table
Also only a quick reply due to data not having been supplied as simple text (attached, or simply pasted into the post, preferably within a
[code]...[/code]
block) but be sure to note the column
utility. I.e.,Code: Select all
rene@hp8k:~$ cat foo.csv
a,bb,ccc,dddd,eee,ff,g
1,2,3,4,5,6,7
iiii,iii,ii,i,ii,iii,iiii
rene@hp8k:~$ column -ts, foo.csv
a bb ccc dddd eee ff g
1 2 3 4 5 6 7
iiii iii ii i ii iii iiii
-
- Level 1
- Posts: 45
- Joined: Fri Jul 10, 2020 7:09 pm
Re: Script command for make a table
I recieved the original data in a libreoffice calc, like this:
Then I need to build the script to view this data via terminal
Then I need to build the script to view this data via terminal
Re: Script command for make a table
Yes. So does
column -ts, infomondia.csv
provide you with something usable for your purposes? man column
for adjustment options.-
- Level 1
- Posts: 45
- Joined: Fri Jul 10, 2020 7:09 pm
Re: Script command for make a table
I made this:
The problem is the second column (he is the "no natural" or fraction part of the first column p.e: 3347383,10=first column. Now the first column is 3347383 and the second column is 10). I need to resolve this ...
The problem is the second column (he is the "no natural" or fraction part of the first column p.e: 3347383,10=first column. Now the first column is 3347383 and the second column is 10). I need to resolve this ...
Re: Script command for make a table
Quoted fields containing comma's. Yah. Sucks.
The proper answer at this point is pointing you to e.g.
What it does is:
1. Turn quoted fields containing a
2. Replace all occurrences of
3. Replace the in step 1 introduced
4. Feed the result to
It's of course important that your data contains neither
The proper answer at this point is pointing you to e.g.
sudo apt-get install csvkit
and its documentation but in a "couldn't help myself" sense: it's very unhelpful that you are still not providing (a sampling of) your data as copy-pastable text rather than as screenshots so I tested this only on your first line:Code: Select all
rene@p55m:~$ cat bcramon.csv
Adelantos y documentos,"$1.455.152,90",$1.424.806,"2,4","2,1","18,6","23,5"
rene@p55m:~$ sed -e 's/"\([^,"]\+\),\([^"]\+\)"/\1|\2/g' -e 's/,/@/g' -e 's/|/,/g' bcramon.csv | column -ts@
Adelantos y documentos $1.455.152,90 $1.424.806 2,4 2,1 18,6 23,5
1. Turn quoted fields containing a
,
into unquoted ones with said ,
replaced by |
2. Replace all occurrences of
,
with @
, i.e., turning comma separated values into @-separated ones.3. Replace the in step 1 introduced
|
with ,
again4. Feed the result to
column
while with -s@
telling it to now consider the input @-separated.It's of course important that your data contains neither
|
nor @
legitimately; any other pair of symbols can be used (or for the former even e.g. the word COMMA) if it does. As already said, only tested on one line due to not wanting to type it all in myself. And as finally also already said, you're in fact much better off with e.g. csvkit
, but, well, ...-
- Level 1
- Posts: 45
- Joined: Fri Jul 10, 2020 7:09 pm
Re: Script command for make a table
Thanks, I would try like this, then I will tell you.
-
- Level 1
- Posts: 45
- Joined: Fri Jul 10, 2020 7:09 pm
Re: [SOLVED] Script command for make a table
Hi rene, in order to a script:
sed -e 's/"\([^,"]\+\),\([^"]\+\)"/\1|\2/g' -e 's/,/@/g' -e 's/|/,/g' ravalider_loffice.csv | column -ts@
works perfectly!
lok at this example
Now i need to automate the circuit:
Dowonload de html page (turn to tmp), convert to csv, with libreoffice calc, make the script to view the data via terminal and make any loop to refresh data.
Thank you so much!
sed -e 's/"\([^,"]\+\),\([^"]\+\)"/\1|\2/g' -e 's/,/@/g' -e 's/|/,/g' ravalider_loffice.csv | column -ts@
works perfectly!
lok at this example
Now i need to automate the circuit:
Dowonload de html page (turn to tmp), convert to csv, with libreoffice calc, make the script to view the data via terminal and make any loop to refresh data.
Thank you so much!
Re: [SOLVED] Script command for make a table
Thanks for reporting; good to know it was useful.