Insertion into csv


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insertion into csv
# 1  
Old 03-11-2011
Insertion into csv

I want to use bash to insert the variable $a into the cell A1 of a csv file mycsv.csv.

How do I insert a variable into a specific cell in a csv file?

Last edited by locoroco; 03-11-2011 at 03:49 AM..
# 2  
Old 03-11-2011
Hi locoroco,

If is comma "," separated, for cell(1,1)=A1
Code:
echo "a1,b1,c1
a2,b2,c2
a3,b3,c3
a4,b4,c4" | awk -F"," 'NR==1{$1="a"$1}1'
aa1 b1 c1
a2,b2,c2
a3,b3,c3
a4,b4,c4

For cell(4,3)=C4
Code:
$ echo "a1,b1,c1
a2,b2,c2
a3,b3,c3
a4,b4,c4" | awk -F"," 'NR==4{$3="a"$3}1'
a1,b1,c1
a2 b2 c2
a3,b3,c3
a4,b4,ac4

Regards
This User Gave Thanks to cgkmal For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Positional insertion for multibyte characters

Hi I have a requirement to insert a dot "." after a position in each line, say 110th position. For which, I have written the below command. cat filename | sed 's/./&\./110' > new_filename The code is working fine, but when we have multi byte (2 or 3) characters in the input file, the... (3 Replies)
Discussion started by: tostay2003
3 Replies

2. Programming

Insertion Sort Error in C++

TD P { margin-bottom: 0in; }P { margin-bottom: 0.08in; }TT.cjk { font-family: "WenQuanYi Zen Hei Sharp",monospace; }A:link { } I am trying to run this program for Insertion Sort, But don't know that why I am getting following Error #include<iostream> int main(){ int i,j,key,n;... (4 Replies)
Discussion started by: liveproject101
4 Replies

3. UNIX for Dummies Questions & Answers

Simple, I think, VIM Insertion

Hey everyone, I recently had to learn how to use UNIX and VIM for an internship, and have run in to a little challenge today. I have lists of thousands of file names that represent CAS (Chemical Abstracts Service) numbers, but they are not formatted correctly. CAS numbers run in the form of... (2 Replies)
Discussion started by: Stuart Ness
2 Replies

4. Shell Programming and Scripting

Insertion in a file

Hi All, I want to insert a line just befor the lst line in a file. please can anyone advise. Cheers, Shazin (3 Replies)
Discussion started by: Shazin
3 Replies

5. Shell Programming and Scripting

insertion of text from sed script

Hi , This is my first thread ; facing some issues withmy sed script I need to insert the code from my log file which is between two keywords. content is like this ........ log ############################ log1 log2 231 "Ban" "tom" and the line one of the cross line friend... (2 Replies)
Discussion started by: shalini_008
2 Replies

6. Shell Programming and Scripting

Insertion of Header record

A header record is to be inserted in the begining of a flat file without using extra file or new file. It should be inserted into same file. Advace thanks for all help... (7 Replies)
Discussion started by: shreekrishnagd
7 Replies

7. UNIX for Dummies Questions & Answers

insertion sort???

Hi, I was wondering if someone here could help me figure out what's wrong with this simple insertion sort shell script. This is the output I get when I try to run it: "23 43 22 15 63 43 23 11 10 2 ./insertion.sh: line 23: 23 43 22 15 63 43 23 11 10 2 And here's the script: ... (2 Replies)
Discussion started by: sogpop
2 Replies

8. Shell Programming and Scripting

automatic header insertion

hi Is there any way to automatically insert a predefined header into a file? It would include the file name, author name, date and a description, the description entered on the first line of vi. Thanks for any help Oliver (4 Replies)
Discussion started by: olimiles
4 Replies

9. AIX

problem with Unicode characters insertion

hi, I have a problem with unicode chars ( chinese, japanese etc ) insertion using sqlplus prompt. When i wrote a proc program for it i am able to create records. But when i fore the same query on sql prompt it stores reverse ????? ..some junk. widechar columns are mapped with NVARCHAR datatype.... (0 Replies)
Discussion started by: suman_jakkula
0 Replies

10. UNIX for Advanced & Expert Users

Insertion of Leap Second

Hi All, We are running the HP-UX 11.11 and Linux AS 3.0. so, shall we need to make any changes for leap second i.e. insert the leap second on 1st Jan 2006 or does the system have some setup which would take care of this automatically. Please advise. Regards, Inder (2 Replies)
Discussion started by: isingh786
2 Replies
Login or Register to Ask a Question