Sponsored Content
Top Forums Shell Programming and Scripting Inserting new fields to a csv file Post 302847919 by midhun19 on Wednesday 28th of August 2013 05:03:04 AM
Old 08-28-2013
Inserting new fields to a csv file

hi
I have a csv file with few rows

Code:
 
> cat job_stat
1,jobname1,somthing,somthing
2,jobname2,somthing,somthing
3,jobname3,somthing,somthing
4,jobname4,somthing,somthing

I want to add few columns after the 2nd column and then append rest of the columns after the 3rd newly added column.
After adding fields the file should look like this
Code:
 
1,jobname1,status,starttime,somthing,somthing
2,jobname2,status,starttime,somthing,somthing
3,jobname3,status,starttime,somthing,somthing
4,jobname4,status,starttime,somthing,somthing

I can do this by iterating line through the lines
Code:
(echo $string | cut -d "," -f -2) appended with ('status,starttime,') appended with (echo $string | cut -d "," -f 3-)

redirecting to a new file and renaming the new file to original file once all the lines are processed.
Is there any easy way to do this in awk or sed.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to work with fields of a csv file?

I need to insert data into a perticular field of a csv file, lets say second field. Can any one help me to do this? I found that we can do it with sed. can any one guide me to accomplish this? thanks in advance. (12 Replies)
Discussion started by: praveen_b744
12 Replies

2. Shell Programming and Scripting

How to create a CSV File by reading fields from separate files

SHELL SCRIPT Hi, I have 3 separate files within a folder. Every File contains data in a single column like File1 contains data mayank sushant dheeraj File2 contains DSA_AT MG_AT FLAT_09 File3 contains data 123123 232323 (2 Replies)
Discussion started by: mayanksargoch
2 Replies

3. Shell Programming and Scripting

pulling different fields from a csv file

Hi, I have a requirment where I need to pull different columns from a .csv file. Here is the sample of the csv file. account,item,flag1,flag2,flag3,flag4,flag5,......feed,tran I will be have a config.txt file which will have the following information. item,flag5,flag10,feed,tran... (2 Replies)
Discussion started by: akdevula
2 Replies

4. Shell Programming and Scripting

Comparing two csv file fields using awk script

Hi All, I want to remove the rows from File1.csv by comparing the columns/fields in the File2.csv. I only need the records whose first column is same and the second column is different for the same record in both files.Here is an example on what I need. File1.csv: RAJAK|ACTIVE|1... (2 Replies)
Discussion started by: rajak.net
2 Replies

5. Shell Programming and Scripting

Inserting additional comma delimiters in a csv file, after and before certian fields.

Hello I have a csv file which I need to insert addtional commas into. The csv is of the format field1,field2,field3,field4,...etc...,field13,field14 I need to add extra commas in each record so that the final output looks like ... (1 Reply)
Discussion started by: kamal_p_99
1 Replies

6. Shell Programming and Scripting

Randomly inserting extra columns into csv file

Hi Tech Guru, I have a test file as below , which needs some more fields to be populated randomly : dks3243;12;20130823;1420;25m;0;syt dks3243;rocy;10 dks3243;kiop;18 sde21p4;77;20151210;8479;7py;9;vfr sde21p4;temp;67 sfq6i01;12;20120123;3412;4rd;7;jui sfq6i01;uymk;90 sfq6i01;kiop;51 ... (8 Replies)
Discussion started by: Lokesha
8 Replies

7. Shell Programming and Scripting

Inserting blank columns in already present CSV file

Hi, i have a csv file which have headers and values of it like below : headers --> CI Ref SerialNumber LastScanDate values --> VMware-42,VMware-42,Tue, 20 May 2014 11:03:44 +0000 i want to have a above csv in below format : headers --> CI Name CI Description CI Ref... (6 Replies)
Discussion started by: omkar.jadhav
6 Replies

8. Emergency UNIX and Linux Support

How to convert the following characters in some fields in a csv file?

I have a csv file which is produced out of a SED command sed 's/|/","/g; s/^/"/; s/$/"/' A4.txt > A5.csv and I need either an addition to the SED command or a separate command to convert the following characters which occur within the fields in multiple lines 1) "=" to =" and 2)""~ to " (4 Replies)
Discussion started by: etldev
4 Replies

9. UNIX for Beginners Questions & Answers

How to count lines of CSV file where 2 fields match variables?

I'm trying to use awk to count the occurrences of two matching fields of a CSV file. For instance, for data that looks like this... Joe,Blue,Yes,No,High Mike,Blue,Yes,Yes,Low Joe,Red,No,No,Low Joe,Red,Yes,Yes,Low I've been trying to use code like this... countvar=`awk ' $2~/$color/... (4 Replies)
Discussion started by: nmoore2843
4 Replies

10. Shell Programming and Scripting

Matching two fields in two csv files, create new file and append match

I am trying to parse two csv files and make a match in one column then print the entire file to a new file and append an additional column that gives description from the match to the new file. If a match is not made, I would like to add "NA" to the end of the file Command that Ive been using... (6 Replies)
Discussion started by: dis0wned
6 Replies
Text::CSV::Encoded::Coder::EncodeGuess(3pm)		User Contributed Perl Documentation	       Text::CSV::Encoded::Coder::EncodeGuess(3pm)

NAME
Text::CSV::Encoded::Coder::EncodeGuess - Text::CSV::Encoded coder class using Encode::Guess SYNOPSIS
use Text::CSV::Encoded coder_class => 'Text::CSV::Encoded::Coder::EncodeGuess'; use Spreadsheet::ParseExcel; my $csv = Text::CSV::Encoded->new(); $csv->encoding( ['ucs2', 'ascii'] ); # guessing ucs2 or ascii? $csv->encoding_to_combine('shiftjis'); my $excel = Spreadsheet::ParseExcel::Workbook->Parse( $file ); my $sheet = $excel->{Worksheet}->[0]; for my $row ( $sheet->{MinRow} .. $sheet->{MaxRow} ) { my @fields; for my $col ( $sheet->{MinCol} .. $sheet->{MaxCol} ) { my $cell = $sheet->{Cells}[$row][$col]; push @fields, $cell->{Val}; } $csv->combine( @fields ) or die; print $csv->string, " "; } DESCRIPTION
This module is inherited from Text::CSV::Encoded::Coder::Encode. USE
Except for 2 attributes, same as Text::CSV::Encoded::Coder::Encode. encoding_in $csv = $csv->encoding_in( $encoding_list_ref ); The accessor to an encoding for pre-parsing CSV strings. If no encoding is given, returns current $encoding, otherwise the object itself. $encoding_list_ref = $csv->encoding_in() When you pass a list reference, it might guess the encoding from the given list. $csv->encoding_in( ['shiftjis', 'euc-jp', 'iso-20022-jp'] ); If it cannot guess the encoding, the first encoding of the list is used. encoding $csv = $csv->encoding( $encoding_list_ref ); $encoding_list_ref = $csv->encoding(); You can pass a list reference to this attribute only: * For list data consumed by combine(). * For list reference returned by getline(). In other word, in "combine" and "print", it might guess an encoding for the passing list data. If it cannot guess the encoding, the first encoding of the list is used. SEE ALSO
Encode, Encode::Guess AUTHOR
Makamaka Hannyaharamitu, <makamaka[at]cpan.org> COPYRIGHT AND LICENSE
Copyright 2008-2010 by Makamaka Hannyaharamitu This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2010-04-26 Text::CSV::Encoded::Coder::EncodeGuess(3pm)
All times are GMT -4. The time now is 04:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy