Help in adding in csv file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Help in adding in csv file
# 1  
Old 05-13-2011
Network Help in adding in csv file

Hi experts
I have a .csv file which contains
the csv is comma seperated file
col1 col2
1 2
3 4
5 6
7 8

I want the colums to be added and the output must be

col1 col2 col3
1 2 3
3 4 7
5 6 11
7 8 15

Please helpSmilie
# 2  
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:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
Login or Register to Ask a Question