Sponsored Content
Full Discussion: Reformat csv file
Top Forums Shell Programming and Scripting Reformat csv file Post 302887201 by jamaje on Thursday 6th of February 2014 10:26:35 AM
Old 02-06-2014
Reformat csv file

Hi,

I have a csv file with content like:
Code:
1,0,100
1,1,150
2,0,200
2,1,250
3,0,300
3,1,350

I want an output such that all numbers in 3rd col where 2nd col is "0" come in the same col in the output. The same goes for numbers where 2nd col is "1".
Code:
1 100 150
2 200 250
3 300 350

Tnx

Moderator's Comments:
Mod Comment Please use code tags for your code and data next time

Last edited by vbe; 02-06-2014 at 11:45 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

reformat the file

Hi all, I ran into this problem, hope you can help I have a text file like this: Spriden ID First Name Last Name Term Code Detail Code Amount Trans Date Description ... (3 Replies)
Discussion started by: CamTu
3 Replies

2. Shell Programming and Scripting

Insert blanks for missing fields and reformat to csv

I am trying to process inventory addition files for insertion into a MySQL database. The format convention is book UIEE. If the field for the add file has no data, the field is NOT included in the upload file, so I need to add a blank/empty for any missing fields. The I need to create a csv or tsv... (9 Replies)
Discussion started by: LoveSquid
9 Replies

3. Shell Programming and Scripting

Please help me reformat this file

I am working with a file of the form; 4256 7726 1 6525 716 1 7626 0838 1 8726 7623 2 8625 1563 2 1662 2628 3 1551 3552 3 1542 7984 ... (3 Replies)
Discussion started by: digipak
3 Replies

4. Shell Programming and Scripting

Reformat a file

I have a csv file with 11 columns. The first columns contains the User Id. One User id can have multiple sub Id. The value of Sub Id is in column 10. 100026,captjason@hawaii.rr.com ,jason ,wolford ,1/16/1969, ,US, ,96761 ,15 ,seg_id 100026,captjason@hawaii.rr.com ,jason ,wolford ,1/16/1969,... (3 Replies)
Discussion started by: r_t_1601
3 Replies

5. Shell Programming and Scripting

Reformat file using nawk

Hi all, I have a file with records that look something like this, "Transaction ID",Date,Email,"Card Type",Amount,"NETBANX Ref","Root Ref","Transaction Type","Merchant Ref",Status,"Interface ID","Interface Name","User ID" nnnnnnnnn,"21 Nov 2011 00:10:47",someone@hotmail.co.uk,"Visa... (2 Replies)
Discussion started by: dazedandconfuse
2 Replies

6. Shell Programming and Scripting

awk reformat file

Hello: When I tried a perl-oneliner to re-format fasta file. infile.fasta >YAL069W-1.334 Putative promoter CCACACCACACCCACACACC ACACCACACCCACACACACA ACAGCCCTAATCTAACCC >YAL068C-7235.2170 Putative ABC sequence TACGAGAATAATTT ACGTAAATGAAGTT TATATATAAA >gi|31044174|gb|AY143560.1|... (15 Replies)
Discussion started by: yifangt
15 Replies

7. Shell Programming and Scripting

[Solved] File reformat

I am using the code below to reformat the input (hp.txt). The output (newhp.txt) is not in the desired format and I can not seem to figure it out. I have attached both. Thank you. perl -aF/\\t/ -lne 'print join(" ",@F) for ("0 A","0 G","0 C","0 T","A 0","G 0","C 0","T 0")' hp.txt > newhp.txt ... (4 Replies)
Discussion started by: cmccabe
4 Replies

8. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

9. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies
FREETABLE(1)							     Freetable							      FREETABLE(1)

NAME
freetable - tool for making HTML tables generation easier VERSION
This manpage describes version 2.3 of freetable. It might be not 100% accurate if you use different version. SYNOPSIS
freetable [options] filename or freetable [options] Possible options are : -h, --help Print usage info and exit -V, --version Print version information and exit -c, --comment Insert comment before every cell to point its location -b, --no-nbsp Do not insert &nbsp; to empty cells for lowered-3D apperance -w, --warning Print a warning before each generated table that you should not change it. You should change its source. -l, --location Substitute <row> and <col> flags inside table with correct cell's location -m, --macro [program] Use macro procesor to proces cells content (default: m4) WARNING
DO NOT USE MACRO PROCESSOR OVER UNSURE SOURCE M4 MAY BE USED TO COMPROMISE YOUR SECURITY FOR MORE INFORMATION ON THIS EXEC : info m4 'UNIX commands' syscmd DESCRIPTION
This is free replacement of wwwtable HTML is great language, but have one horrible flaw : tables. I spent many hours looking at HTML source I just written and trying to guess which cell in source is which in browser. If this also describes you, then read this manpage and your pain will stop. Program read HTML source from either stdin or file. Then it searches for line starting table: <wwwtable [options]> Then it analyzes table, put correct HTML table in this place and continue searching for the next table. TABLE SYNTAX
It is very easy: wwwtable : <wwwtable [wwwtable_options]> [preamble] [cell] [cell] ... </wwwtable> wwwtable_options will be passed to <table> tags. There is no magic inside preamble. It can be any HTML text. It will be simply put in front of table. cell is either normal_cell (<td> tag) or header_cell (<th> tag). At least it was this way in freetable 1.x. See the next section for alternative cell address syntax. normal_cell : (row,col) cell_options cell_content header_cell : ((row,col)) cell_options cell_content cell_options will be passed to cell tag. There is magic inside colspan and rowspan keys are parsed to make correct table. cell_content can be anything. It may contain text, tags, and even nested wwwtables. If you use -m (or --macro) option, it will be passed thru m4(1), with <row> and <col> set to adress of curent cell row and col are either numbers locating cells, expressions relative to previous cell or regular expresions to match few of them. Unlike wwwtable, freetable can use regular expresions for header cells. Also * can be used, and it mean .* really. Relative expressions are : = or empty means : the same as previous + or +X means : one and X more than previous - or -X means : one and X less than previous If many definisions adress the same cell all options and contents are concatenated in order of apperance. If you want to use only regular expresions you must tell program about the last cell : <wwwtable> (*,1) these are colums 1 (1,*) these are rows 1 (4,4) </wwwtable> ALTERNATIVE CELL ADDRESS SYNTAX
It is inconvenient to specify cell address as regular expression. So in freetable 2.0 two new methods were introduced. Both can be used to either normal or header cells. Full bakward compatibility is preserved. To preserve it, new syntax had to be introduced. Unfortunatelly, you can't specify row address using one method, and column address using another. To come around this, both new methods are very liberal and allow you to use =, +, -, +X -X and null string with the same meaning as they have in old addressing method. Unlike regular expression method, new methods will find out the last cell automatically. EXPLICIT RANGES (rowrange;colrange) cell_options cell_content Syntax for both rowrange and colrange is like: 1-2,4-7,9,12. Duplicates will be eliminated. For purpose of relative addresses last given number is used. So if you write (1-100,32;1) foo (+,) bar Cell (33,1) will contain `foobar' and all others only `foo'. ARBITRARY PERL CODE ({code for rows},{code for tables}) cell_options cell_content You can use arbitrary Perl one-liner as long as it matches our not very intelligent regular expressions and evaluates to list. Unfortu- natelly there isn't any regular expression for Perl code, but as long as it doesn't contain },{ and }) it should work. Example: <wwwtable> ({grep {$_%3 == 1} 1..100},{1..2,4}) foo </wwwtable> Will evaluate to 100 rows x 4 columns table with `foo' in every 1st, 2nd and 4th column of every row with number equal 1 modulo 3. If you want to use "arbitrary code" in one part of address and explicit range in the other, change - into .. in defenition of range, and put in between { and }. If you want to use "arbitrary code" in one part of address and regular expression in the other, you have to write {grep {/expression/} from..to}. Unfortunatelly, in this case you have to specify size of the table explicitely. INCOMPATIBILITIES WITH WWWTABLE
If you was formerly user of wwwtable and want to change your tool, you should read this. Most of this is about regexps handling. Notice also that wwwtable couldnt do location tags substitution nor macroprocesing. Option -w has completely oposite meaning. We dont print warnings by default, and -w or --warning is used to force warnings. Table header fields can be specified by regexps ex : ((1,*)) It was impossible in wwwtable. Axis counters are 100% orthogonal. This mean that code : (*,1) width=30 (*,2) width=35 (*,3) width=40 (=,=) Foo Foo will appear in 3rd column. If you wanted it to be in 1st you should write : (*,1) width=30 (*,2) width=35 (*,3) width=40 (=,1) Foo or (*,) width=30 (*,+) width=35 (*,+) width=40 (=,1) Foo In freetable 2.0 two new methods o specifying cell address were introduced. They are completely incompatible with wwwtable. BUGS
"Arbitrary Perl Code" cell address will fail on very complex Perl code. SEE ALSO
m4(1) AUTHOR
Tomasz Wegrzanowski <taw@users.sourceforge.net> perl v5.8.8 2001-12-02 FREETABLE(1)
All times are GMT -4. The time now is 07:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy