populate specified value in csv


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting populate specified value in csv
# 1  
Old 01-05-2011
populate specified value in csv

Hi,

I've requirement of populating two blank column ( 4rth and 6th ) in a csv file with specified value for all the rows having value within the first colmn.

I know it can be done with sed, as given in the below command, but i am not sure how pull blank value or specify target column etc or check for rows having values etc.

please help.

Code:
sed 's\:\\DTF\!g' file

Thanks, John
# 2  
Old 01-05-2011
Post an example of your input file and the desired output.
# 3  
Old 01-05-2011
Code:
Input File : 

mail1@abc.com,xyz,abc,,33938,,United States
mail2@abc.com,xxx,aaa,,33939,,United States

Output File:

mail1@abc.com,xyz,abc,DTP,33938,DSS,United States
mail2@abc.com,xxx,aaa,DTP,33939,DSS,United States

Thanks !
# 4  
Old 01-05-2011
Quote:
Originally Posted by john_prince
I've requirement of populating two blank column ( 4rth and 6th ) in a csv file with specified value for all the rows having value within the first colmn.
Try this:
Code:
awk -F, '$1{$4="DTP"; $6="DSS"}1' OFS=\, file


Last edited by Franklin52; 01-05-2011 at 02:22 PM..
This User Gave Thanks to Franklin52 For This Post:
# 5  
Old 01-05-2011
Try this,
Code:
sed 's/,,/,DTP,/ ;s/,,/,DSS,/'  inputfile

This User Gave Thanks to pravin27 For This Post:
# 6  
Old 01-05-2011
Thanks, it is working, but not at the right place. Actually, it has quotes within each fields.

Code:
"mail1@abc.com","xyz","abc","","33938","","United States"
"mail2@abc.com","xxx","aaa","","33939","","United States"

Could you adjust the command likewise?

---------- Post updated at 10:38 AM ---------- Previous update was at 10:37 AM ----------

Pravin,

This is not working - it says command garbled.


sed 's/,,/,DTP,/ ;s/,,/,DSS,/' justmailtest.csv > justmailtest_out.csv
sed: command garbled: s/,,/,DTP,/ ;s/,,/,DSS,/
# 7  
Old 01-05-2011
Code:
awk -F, '$1{$4="\"DTP\""; $6="\"DSS\""}1' OFS=\, file

You want to populate the columns only in the lines with a value in the 1e column, right?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script to populate (2) values in .XML

Good Afternoon Team - I"m asking for assistance on a piece of code to populate two values in an XML file. I have it working perfectly using CScript for DOS, but I have a need to do that same process in a Linux environment. Here is the XML I need to modify: <?xml version="1.0"... (5 Replies)
Discussion started by: SIMMS7400
5 Replies

2. Shell Programming and Scripting

Populate Column Value Using AWK

Hi All, I am trying to find out awk one liner for the following requirement but failed in doing that. I have two files. Content of first file: file1.txt SUCCESS A file2.txt SUCCESS B file3.txt SUCCESS A file4.txt FAIL ... (7 Replies)
Discussion started by: angshuman
7 Replies

3. Shell Programming and Scripting

Shell script to populate an array from a csv file

Hi Guys, I've got a script that runs and collects statistics from one of our machines and outputs the data into a csv file. Now, that script runs fine and I managed to create another one (with a lot of help from this forum!!) to trim the csv file down to all the data that I need, rather than all... (9 Replies)
Discussion started by: jimbob01
9 Replies

4. Shell Programming and Scripting

Create files from a list and then populate them

I have a list of filenames that I want created - they must be created via a certain naming convention due to the software I'm using. Once they are created I have another file that will be used to populate them with data. So far this is what I have: #For each line in text file "foo_txt" create... (2 Replies)
Discussion started by: MaindotC
2 Replies

5. Shell Programming and Scripting

Using eval to populate an array in the background

Hi. I am trying to populate an array using eval in the background within a function. So this function will create a list of 3 character directories from SVN and store in an array. I want to call this function when the script starts in the background unknown to the user. The problem is that... (2 Replies)
Discussion started by: jmiaebrown
2 Replies

6. Shell Programming and Scripting

populate a bash variable from an awk operation

Hi, I'm trying to populate bash script variable, data_size with the size of the largest file in my current directory data_size=$(ls -lS | grep -v "total" | head -1) | awk '{ print $5 }' I've tried adding an echo before the call to awk data_size=$(ls -l | grep -v "total" | head -1) |... (2 Replies)
Discussion started by: mark_s_g
2 Replies

7. Shell Programming and Scripting

PHP populate variable with function

Hi, I've a php scirpt that calls in an external class. The external class, myClass, has several public and private functions. There is one public function which derives a value that I want be able to bring it to the main php scirpt. Here is the code. ....snip.... include... (1 Reply)
Discussion started by: nitin
1 Replies

8. Shell Programming and Scripting

populate PERL Hash

Hello I am new to perl and learning ...can you please explain why am i getting this error...as myHash is defined right above the code and I think it should be avilable in the sub function. Here is my code: <code> #!/usr/bin/perl use warnings; use strict; %myHash=(); sub... (2 Replies)
Discussion started by: uandme2k2
2 Replies

9. Shell Programming and Scripting

populate variable from remote result

Hi there i am trying to pass the result of a remote command into a variable into my script ie #!/bin/sh var = `ssh remote_box 'uname'` echo $var but all i get back is ./script.sh: var: not found However when i add a -x to put it into diag mode i get the following + ssh... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

10. Shell Programming and Scripting

using the getline to populate an array from a file

Hello, I am trying to use the awk getline command to populate an array from a flat file. Has anyone done this before? So we have file1: a b c d I want to create an array like index that contains these four elements (8 Replies)
Discussion started by: penfold
8 Replies
Login or Register to Ask a Question