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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting additional comma delimiters in a csv file, after and before certian fields.
# 1  
Old 03-28-2012
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

field1,field2,field3,field4,...etc...,field13,,,,field14,,,,,,,,

So specifically 3 addtional fields before the last field and a further 8 after.

There are no headers or footers in this file.

Is there a way of using sed or cut inorder to do this?

K
# 2  
Old 03-28-2012
Code:
sed "s/,[a-zA-Z0-9]*$/,,,&,,,,,,,,/"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to extract fields from a CSV i.e comma separated where some of the fields having comma as value?

can anyone help me!!!! How to I parse the CSV file file name : abc.csv (csv file) The above file containing data like abv,sfs,,hju,',',jkk wff,fst,,rgr,',',rgr ere,edf,erg,',',rgr,rgr I have a requirement like i have to extract different field and assign them into different... (4 Replies)
Discussion started by: J.Jena
4 Replies

2. Shell Programming and Scripting

Getting fields from a file having multiple delimiters

Hi All, I have a file with a single row having the following text ABC.ABC.ABC,Database,New123,DBNAME,F,ABC.ABC.ABC_APP,"@FUNCTION1("ENT1") ,@FUNCTION2("ENT2")",R, I want an output in the following format ABC.ABC.ABC DBNAME ABC.ABC.ABC_APP '@FUNCTION1("ENT1")... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

3. Shell Programming and Scripting

awk to extract multiple values from file and add two additional fields

In the attached file I am trying to use awk to extract multiple values and create the tab-delimited desired output. In the output R_Index is a the sequential # and Pre_Enrichment is defaulted to .. I can extract from the values to the side of the keywords, but most are above and I can not... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

Inserting Delimiters

Hi Team, I am trying to get the data in below format Jan 01 | 19:00:32 | xyz | abc | sometext | string however I am not sure of the total number strings which can come in the record hence i cant use something like below as it can end $6 or it can go further cat file| awk... (8 Replies)
Discussion started by: rakesh_411
8 Replies

5. Shell Programming and Scripting

Inserting new fields to a csv file

hi I have a csv file with few rows > 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... (3 Replies)
Discussion started by: midhun19
3 Replies

6. Shell Programming and Scripting

Insert data between comma delimiters-large file

Having a huge file in the following format. 2,3,1,,,4 1,2,3,,,,,5, 8,7,3,4,,,, Output needed is: 2,3,1,0.0,0.0,4 1,2,3,0.0,0.0,0.0,0.0,5, 8,7,3,4,0.0,0.0,0.0, I have tried reading the file each line, using AWK to parse to find out ",," and then insert 0.0 . It works but very slow. Need... (8 Replies)
Discussion started by: wincrazy
8 Replies

7. Shell Programming and Scripting

Need Help - comma inside double quote in comma separated csv,

Hello there, I have a comma separated csv , and all the text field is wrapped by double quote. Issue is some text field contain comma as well inside double quote. so it is difficult to process. Input in the csv file is , 1,234,"abc,12,gh","GH234TY",34 I need output like below,... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

8. Shell Programming and Scripting

Inserting string in between field in comma separated file

Hello Mates, I have one txt file having commo seperated values. I have to insert string "FALSE" in 2nd field from the end. E.G SE18 6RN,,,,5439070,1786840,,1000002148671600,123434 Out put should be: SE18 6RN,,,,5439070,1786840,FALSE,1000002148671600,123434 Can some one help me to... (8 Replies)
Discussion started by: krsnadasa
8 Replies

9. Shell Programming and Scripting

add a additional column in csv file

Thanks for allwoing me to discuss in this forum GIVEN BELOW A simple shell script which will ask for the user to input a PC name and it will produce the output in CSV with the PC name #! /bin/bash read -p "enter the PC name :" pc #checking for netstat report netstat -pant |sed '1,2d'... (1 Reply)
Discussion started by: ayyappancheta
1 Replies

10. UNIX for Dummies Questions & Answers

Sort the fields in a comma delimited file

Hi, I have a comma delimited file. I want to sort the fields alphabetically and again store them in a comma delimited file. For example, My file looks like this. abc,aaa,xyz,xxx,def pqr,ggg,eee,iii,qqq zyx,lmo,pqr,abc,fff and I want my output to look like this, all fields sorted... (3 Replies)
Discussion started by: swethapatil
3 Replies
Login or Register to Ask a Question