Sponsored Content
Top Forums Shell Programming and Scripting Append data to new row in CSV file every day Post 302661493 by ranjancom2000 on Monday 25th of June 2012 09:59:07 AM
Old 06-25-2012
Append data to new row in CSV file every day

Hi All

I will run the same script every day in corn and output should go to same CSV file but in different row with dates on it. Below is my example in attached format.

Script i am using to collect switch port online

Code:
DATE=`date '+%d-%m-%y'`
for f in `cat /home/user/switch-ip/switch-ip-test.txt`
do
     echo $f-[$DATE] >> /home/user/switch-ip/switch-nolight.csv
     plink -ssh -v chrrbs@$f -pw secure01 switchshow |grep "No_Light" >> /home/user/switch-ip/switch-nolight.csv
done

Moderator's Comments:
Mod Comment Please use code tags, not quote-tags, thanks!

Last edited by zaxxon; 06-25-2012 at 11:04 AM.. Reason: code tags, see PM
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies

2. Shell Programming and Scripting

to append data in a single row

Hi all, I need a logic in UNIX to append contents of a file in same row, where the original contents are found one below the other. For example. My i/p file contains: “user1”,”employee1”,”04/28/2009” “5678” “78” “user2”,”employee2”,”04/30/2009” I want my output... (8 Replies)
Discussion started by: Sgiri1
8 Replies

3. Shell Programming and Scripting

Append Header in CSV file

Hi, I create a csv file and the output looks like below Arun,E001 Sathish,E003 Now i need to include the below header and the output should like below Name,Number Arun,E001 Sathish,E003 Please guide me. Thanks (4 Replies)
Discussion started by: Sekar1
4 Replies

4. Shell Programming and Scripting

Append Second Row to First Row @ end in a file

Hi I want to append line 2n to 2n-1 line where n=1...LastLine in my file. eg: Actual File: Hello Everyone Welcome TO Unix I need Your help Required File: HelloEveryone WelcomeTO Unix I needYour help (5 Replies)
Discussion started by: dashing201
5 Replies

5. Shell Programming and Scripting

I want to append data to same .csv file.

I have a script which has to be scheduled to run 3 times a day. My script picks the required fields from logfile and stores the data in a.csv file. Sample data. my logfile contain: 0097A,0374D,100903,1519,00000606191 0097A,C88RA,100903,0724,00000606105 So the output of first execution... (3 Replies)
Discussion started by: shrima.pratima
3 Replies

6. UNIX for Dummies Questions & Answers

append column and row header to a file in awk script.

Hi! Is there a way to append column and row header to a file in awk script. For example if I have Jane F 39 manager Carlos M 40 system administrator Sam F 20 programmer and I want it to be # name gend age occup 1 Jane F 39 manager 2 Carlos M ... (4 Replies)
Discussion started by: FUTURE_EINSTEIN
4 Replies

7. Shell Programming and Scripting

Read line from the file and append it to each row

Hi All, We have a file in the following format: 0.010000 $ ITI 11 LV2 $ 40456211 $ 0.135000 $ ITI 11 LV1 $ 40512211 $ 1.215600 $ ITI 11 ITI3 $ 41406211 $ 24/05/2014 14:05:02 0.030000 $ ITI 11 LV2 $ 40456211 $ ... (3 Replies)
Discussion started by: gauravsinghal79
3 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

Row Count in .csv file

Hi, I have to find the count of rows starting with "E," in given a.csv file . Sample Data File. E,2333AED,A,MC3,25,31-MAY-18 E,2333AED,A,MC3,25,31-MAY-18 CYMC3 25AED 0000 E,2333CZK,A,MC3,25,31-MAY-18 CYMC3 25CZK 0000 E,2333EUR,A,MC3,25,31-MAY-18... (3 Replies)
Discussion started by: Prabhakar Y
3 Replies

10. Programming

Python script to run multiple command and append data in output csv file

Experts, I am writing a script and able to write only small piece of code and not able to collect logic to complete this task. In input file have to look for name like like this (BGL_HSR_901_1AG_A_CR9KTR10) before sh iss neors. Record this (BGL_HSR_901_1AG_A_CR9KTR10) in csv file Now have to... (0 Replies)
Discussion started by: as7951
0 Replies
FGETCSV(3)								 1								FGETCSV(3)

fgetcsv - Gets line from file pointer and parse for CSV fields

SYNOPSIS
array fgetcsv (resource $handle, [int $length], [string $delimiter = ","], [string $enclosure = '"'], [string $escape = " DESCRIPTION
Similar to fgets(3) except that fgetcsv(3) parses the line it reads for fields in CSV format and returns an array containing the fields read. PARAMETERS
o $handle - A valid file pointer to a file successfully opened by fopen(3), popen(3), or fsockopen(3). o $length - Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). It became optional in PHP 5. Omitting this parameter (or setting it to 0 in PHP 5.1.0 and later) the maximum line length is not limited, which is slightly slower. o $delimiter - The optional $delimiter parameter sets the field delimiter (one character only). o $enclosure - The optional $enclosure parameter sets the field enclosure character (one character only). o $escape - The optional $escape parameter sets the escape character (one character only). RETURN VALUES
Returns an indexed array containing the fields read. Note A blank line in a CSV file will be returned as an array comprising a single null field, and will not be treated as an error. Note If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem. fgetcsv(3) returns NULL if an invalid $handle is supplied or FALSE on other errors, including end of file. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | The $escape parameter was added | | | | | 5.1.0 | | | | | | | The $length is now optional. Default is 0, mean- | | | ing no length limit. | | | | | 4.3.5 | | | | | | | fgetcsv(3) is now binary safe | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 Read and print the entire contents of a CSV file <?php $row = 1; if (($handle = fopen("test.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p> "; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br /> "; } } fclose($handle); } ?> NOTES
Note Locale setting is taken into account by this function. If $LANG is e.g. en_US.UTF-8, files in one-byte encoding are read wrong by this function. SEE ALSO
str_getcsv(3), explode(3), file(3), pack(3), fputcsv(3). PHP Documentation Group FGETCSV(3)
All times are GMT -4. The time now is 12:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy