Sponsored Content
Full Discussion: Help in adding in csv file
Top Forums UNIX for Advanced & Expert Users Help in adding in csv file Post 302521980 by hergp on Friday 13th of May 2011 03:03:57 AM
Old 05-13-2011
Code:
$ nawk  'BEGIN { FS=","; OFS="," } NR == 1 { print $1,$2,"col3" } NR > 1 { print $1,$2,$1+$2} ' inputfile
col1,col2,col3
1,2,3
3,4,7
5,6,11
7,8,15

If your field separator is really blank, as shown in your example, just remove the BEGIN-block.
Code:
$ nawk  'NR == 1 { print $1,$2,"col3" } NR > 1 { print $1,$2,$1+$2} ' inputfile
col1 col2 col3
1 2 3
3 4 7
5 6 11
7 8 15

This User Gave Thanks to hergp For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: adding columns in CSV file with information in each

Hi Wise UNIX Crew, I want to add 3 different columns to the file in which: 1. The first new column pulls in today's date and time 2. Second column one has a '0' 3. Third column has the word 'ANY' going down the column If my file content is as follows: "7","a","abc",123"... (1 Reply)
Discussion started by: dolo21taf
1 Replies

2. UNIX for Advanced & Expert Users

Adding columns in csv

I have the following data in FILE1.CSV: code: Amount1: Amount2: xxxxx ,, 200 ,,400 yyxxa ,,200 bbcgu ,,2500 ,,300 i want to be able to produce the following FILE2.CSV: code: Amount xxxxx ,, 600... (7 Replies)
Discussion started by: chachabronson
7 Replies

3. Shell Programming and Scripting

csv file - adding total to a trailer record

Hi, I have a script which creates and modifies a csv file. I have managed to do everything I need to do apart from 1 thing. I need to append a trailer record to the file. I need this line to hold the total of an entire column of the csv file (skipping the 1st line which is a header). Can... (2 Replies)
Discussion started by: mcclunyboy
2 Replies

4. Shell Programming and Scripting

Help needed: Adding columns in csv file in loop

Hi Everyone: My shell script creates multiple csv files (~30) in for loop. I want to compile (or merge) 3rd column from each (all) of these files to another file (in loop). Please help. Thanks. (3 Replies)
Discussion started by: smap007
3 Replies

5. Shell Programming and Scripting

adding quotes around each column in a csv file

I saved the csv file in a comma delimited format. Sample input input.csv 1 abc 2 2 def 4 3 ghi 6 4 jkl 8 5 mno 10 output.csv should look like this with single quotes around each field '1' 'abc' '2' '2' 'def' '4' '3' 'ghi' '6' '4' 'jkl' '8' '5' 'mno' '10' Please help me :confused:... (3 Replies)
Discussion started by: melannie
3 Replies

6. Shell Programming and Scripting

Adding Extra Commas to a CSV file

Trying in this forum. Not sure if it is permitted.... but in need of help. Please find the requirements in the below link. https://www.unix.com/unix-dummies-questions-answers/191503-add-extra-commas-csv-file-2.html#post302665179 Thanks in Advance. (1 Reply)
Discussion started by: chillblue
1 Replies

7. Shell Programming and Scripting

Adding a new column to a csv file

Hi, Can anyone please explain me how can I add a new column to a Csv file ? Actaully I am setting one set of commands and creating a CSV file with 4 columns. I am executing another command and it's output should be added as column 5 with a column heading ? Can anyone explain how can... (26 Replies)
Discussion started by: rrb2009
26 Replies

8. Shell Programming and Scripting

Mailx - Adding timestamp in CSV file

Hi allI am mailing csv file to our lotusnote server using shell script. I am using command to get require date/time :date +"%d%b%y-%X%p"File name is :TESTFILE-29Jan14-09:00:00AM.csv.When I am receving this on lotusnote server coming as "00AM.csv" rest of the string is getting truncated. I feel due... (1 Reply)
Discussion started by: krsnadasa
1 Replies

9. Shell Programming and Scripting

Adding new column data in csv from UNIX

Adding new column data in csv from UNIX Hi I need to add new column data daily to existing csv file. Please assist 7/11 7/10 7/9 7/8 space 10 GB 20 GB I was able to generate current day's data in csv but unable to add the previous 30 days data to the same csv Please use code tags,... (2 Replies)
Discussion started by: archana25
2 Replies
Text::FormatTable(3pm)					User Contributed Perl Documentation				    Text::FormatTable(3pm)

NAME
Text::FormatTable - Format text tables SYNOPSIS
my $table = Text::FormatTable->new('r|l'); $table->head('a', 'b'); $table->rule('='); $table->row('c', 'd'); print $table->render(20); DESCRIPTION
Text::FormatTable renders simple tables as text. You pass to the constructor (new) a table format specification similar to LaTeX (e.g. "r|l|5l|R|20L") and you call methods to fill the table data and insert rules. After the data is filled, you call the render method and the table gets formatted as text. Methods: new($format) Create a Text::FormatTable object, the format of each column is specified as a character of the $format string. The following formats are defined: l Left-justified top aligned word-wrapped text. L Left-justified bottom aligned word-wrapped text. r Right-justified top aligned word-wrapped text. R Right-justified bottom aligned word-wrapped text. 10R, 20r, 15L, 12l, Number is fixed width of the column. Justified and aligned word-wrapped text (see above). ' ' A space. | Column separator. head($col1, $col2, ...) Add a header row using $col1, $col2, etc. as cell contents. Note that, at the moment, header rows are treated like normal rows. row($col1, $col2, ...) Add a row with $col1, $col2, etc. as cell contents. rule([$char]) Add an horizontal rule. If $char is specified it will be used as character to draw the rule, otherwise '-' will be used. render([$screen_width]) Return the rendered table formatted with $screen_width or 79 if it is not specified. SEE ALSO
Text::ASCIITable COPYRIGHT
Copyright (c) 2001-2004 Swiss Federal Institute of Technology, Zurich. (c) 2009 Trey Harris All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. CODE REPOSITORY
Git - http://github.com/treyharris/Text-FormatTable/tree/master AUTHOR
David Schweikert <dws@ee.ethz.ch> Maintained by Trey Harris <treyharris@gmail.com> Fixed column width and bottom alignment written by Veselin Slavov <vslavov@creditreform.bg> perl v5.10.0 2009-07-24 Text::FormatTable(3pm)
All times are GMT -4. The time now is 03:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy