Sponsored Content
Special Forums Hardware Filesystems, Disks and Memory manipulate csv file to add columns Post 302098473 by ask.jackal on Monday 4th of December 2006 12:20:00 PM
Old 12-04-2006
awk -F, 'NR==1 {head=$0;next}
{ y4[$3]+=$4;y5[$3]+=$5;y6[$3]+=$6}
END {
print head;
print "sales,"y4["sales"],y5["sales"],y6["sales"];
print "IT," y4["IT"],y5["IT"],y6["IT"];
print "marketing," y4["marketing"],y5["marketing"],y6["marketing"];
}' <data.txt

John Arackal
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add Empty columns at the end of csv file

Hi, Can you please tell me how to add empty columns at the end csv file? Currently there are 6 columns in the csv file. I want to add 35 empty columns at the end of this csv file. Thanks, Tushar (17 Replies)
Discussion started by: Tushar Bendale
17 Replies

2. Shell Programming and Scripting

Add columns in csv file

Hi everybody, I am new here and I need a reel help please A have a csv file and I want to add new in the end of the file Devisce Model,VMGuest Name,Host OS Name, Memory Size Value1,Value2,Value3,Value4 Value5,Value6,Value7,Value8 Value9,Value10,Value11,Value12 And I want to add to new... (3 Replies)
Discussion started by: villebonnais
3 Replies

3. Shell Programming and Scripting

AWK : Add columns in the end of csv file

Hi everybody, I need some help please I have a csv file named masterFile1.csv header1,header2,header3 value1,value2,value3 value4,value5,value6 I am trying to add new columns in the end of the csv to have a new csv file named masterFile2.csv like this :... (3 Replies)
Discussion started by: villebonnais
3 Replies

4. UNIX for Dummies Questions & Answers

Manipulate and move columns in a file

Hello Unix Gurus, I have a request 2 perform several functions on a file, delete columns, delete rows based on column value, and finally move around columns in the final output. Consider the following input file with 12 columns; ... (1 Reply)
Discussion started by: chumsky
1 Replies

5. Linux

Add empty columns at the end of a CSV file

I have a .CSV file (lets say named as file.csv) with numeric and string values. The string might contain commas hence they are enclosed in double quotes as in the below format. column1,column2,column3,column4,column5,column6,column7 12,455,"string, with, quotes, and with, commas, in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

6. Shell Programming and Scripting

Manipulate a CSV File

Hello, How do i manipulate .csv file to this format? Thank you very much. Source: john,5 marco,7 john,4 paul,3 marco,8 Output: john,9 marco,15 (5 Replies)
Discussion started by: tara123
5 Replies

7. Shell Programming and Scripting

awk command to manipulate csv file in UNIX

Hi, I am new to awk/unix and am trying to put together a script to manipulate the date column in a csv file. I have file1.csv with the following contents: Date,ID,Number,Amount,Volume,Size 01-Apr-2014,WERFG,998,105873.96,10873.96,1342.11 01-Apr-2014,POYFR,267,5681.44,5681.44,462.96 I... (2 Replies)
Discussion started by: Prit Siv
2 Replies

8. Shell Programming and Scripting

Add 8 columns at the end of .csv file using awk

Hello all, I have a .csv file of 16 columns consists of bunch of numbers. 6.45E+01 1.17E+01 8.10E+04 8.21E+01 8.50E+00 1.20E+01 1.02E+01 1.88E+01 1.86E+04 3.53E+03 1.09E+07 3.82E+04 2.09E+03 3.57E+03 2.98E+03 3.93E+03 6.34E+01 3.23E+01 9.24E+04 ... (5 Replies)
Discussion started by: Zam_1234
5 Replies

9. Shell Programming and Scripting

awk command to manipulate csv file in UNIX

Hi, I am new to awk and unix programming and trying to manipulate a csv file. My current csv file looks like this: col1,col2,col3,col4,col5,col4,col5,col6,col7,col8 223,V,c,2,4,f,r,,y,z 223,V,c,3,2,f,r,,y,z 223,V,c,1,4,f,r,,y,z 223,V,c,4,3,f,r,,y,z 227,V,c,3,1,f,r,,y,z... (8 Replies)
Discussion started by: Prit Siv
8 Replies

10. Shell Programming and Scripting

To add multiple columns in csv file

Hi Guys, Can you help to add static values at the end of the csv file with headers input_file id,name 1,neo 2,pull Expected id,name,status,entry,g_id 1,neo,done,2019-11-01T07:14:23,pass 2,pull,done,2019-11-01T07:14:23,pass My try but not able replacing properly and unable... (1 Reply)
Discussion started by: Master_Mind
1 Replies
MONGOCOLLECTION.FINDANDMODIFY(3)					 1					  MONGOCOLLECTION.FINDANDMODIFY(3)

MongoCollection::findAndModify - Update a document and return it

SYNOPSIS
public array MongoCollection::findAndModify (array $query, [array $update], [array $fields], [array $options]) DESCRIPTION
The findAndModify command atomically modifies and returns a single document. By default, the returned document does not include the modi- fications made on the update. To return the document with the modifications made on the update, use the $new option. PARAMETERS
o $query - The query criteria to search for. o $update - The update criteria. o $fields - Optionally only return these fields. o $options - An array of options to apply, such as remove the match document from the DB and return it. +----------------+---------------------------------------------------+ | Option | | | | | | | Description | | | | +----------------+---------------------------------------------------+ | $sort array | | | | | | | Determines which document the operation will | | | modify if the query selects multiple documents. | | | findAndModify will modify the first document in | | | the sort order specified by this argument. | | | | |$remove boolean | | | | | | | Optional if $update field exists. When TRUE, | | | removes the selected document. The default is | | | FALSE. | | | | | $update array | | | | | | | Optional if $remove field exists. Performs an | | | update of the selected document. | | | | | $new boolean | | | | | | | Optional. When TRUE, returns the modified docu- | | | ment rather than the original. The findAndModify | | | method ignores the $new option for remove opera- | | | tions. The default is FALSE. | | | | |$upsert boolean | | | | | | | Optional. Used in conjunction with the $update | | | field. When TRUE, the findAndModify command cre- | | | ates a new document if the query returns no docu- | | | ments. The default is false. In MongoDB 2.2, the | | | findAndModify command returns NULL when upsert is | | | TRUE. | | | | | | | | | | | | | | | | +----------------+---------------------------------------------------+ RETURN VALUES
Returns the original document, or the modified document when $new is set. ERRORS
/EXCEPTIONS Throws MongoResultException on failure. EXAMPLES
Example #1 MongoCollection::findAndModify example <?php $m = new Mongo; $col = $m->selectDB("test")->jobs; $col->insert(array( "name" => "Next promo", "inprogress" => false, "priority" => 0, "tasks" => array( "select product", "add inventory", "do placement"), ) ); $col->insert(array( "name" => "Biz report", "inprogress" => false, "priority" => 1, "tasks" => array( "run sales report", "email report" ) ) ); $col->insert(array( "name" => "Biz report", "inprogress" => false, "priority" => 2, "tasks" => array( "run marketing report", "email report" ) ), array("w" => 1) ); $retval = $col->findAndModify( array("inprogress" => false, "name" => "Biz report"), array('$set' => array('inprogress' => true, "started" => new MongoDate())), null, array( "sort" => array("priority" => -1), "new" => true, ) ); var_dump($retval); ?> The above example will output something similar to: array(6) { ["_id"]=> object(MongoId)#7(1) { ["$id"]=> string(24) "5091b5b244415e8cc3000002" } ["inprogress"]=> bool(true) ["name"]=> string(10) "Biz report" ["priority"]=> int(2) ["started"]=> object(MongoDate)#8(2) { ["sec"]=> int(1351726514) ["usec"]=> int(925000) } ["tasks"]=> array(2) { [0]=> string(20) "run marketing report" [1]=> string(12) "email report" } } Example #2 MongoCollection::findAndModify error handling <?php $m = new Mongo; $col = $m->selectDB("test")->jobs; try { $retval = $col->findAndModify( array("inprogress" => false, "name" => "Next promo"), array('$pop' => array("tasks" => -1)), array("tasks" => array('$pop' => array("stuff"))), array("new" => true) ); } catch(MongoResultException $e) { echo $e->getCode(), " : ", $e->getMessage(), " "; var_dump($e->getDocument()); } ?> The above example will output something similar to: 13097 : exception: Unsupported projection option: $pop array(3) { ["errmsg"]=> string(46) "exception: Unsupported projection option: $pop" ["code"]=> int(13097) ["ok"]=> float(0) } SEE ALSO The MongoDB findAndModify command docs. PHP Documentation Group MONGOCOLLECTION.FINDANDMODIFY(3)
All times are GMT -4. The time now is 04:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy