Edit csv file


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

I'm trying to replace the content of cell 4A a csv file with another value. The code itself is successful, but when I try to save the newly changed file content into the old file, it doesn't work:
Code:
awk -F"," 'NR==4{$1="\"newcontent\","$3}1' test.csv | sed 's/ //g' > test.csv

It works only if I save it to another file:
Code:
awk -F"," 'NR==4{$1="\"newcontent\","$3}1' test.csv | sed 's/ //g' > test2.csv

Do I really have to save the changed file content into another file? Maybe I can save it to a temporary file that is removed automatically, and then save that content into the test.csv?

Last edited by Franklin52; 03-11-2011 at 01:54 PM.. Reason: Please use code tags
# 2  
Old 03-11-2011
You can also replace the spaces with the awk command:
Code:
awk -F, 'NR==4{$1="\"newcontent\","$3}{gsub(" ",x)}1' test.csv > temp
mv temp test.csv

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

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

GUI to edit and control csv file

Hello, I manage an application with a lot of parameter files under a csv format. I'm looking for a GUI to allow users to edit those files without breaking them. I would like an admin access to define the format of the files (number of columns, format of each column, list of value possible...).... (0 Replies)
Discussion started by: maturix
0 Replies

2. Shell Programming and Scripting

Save output of updated csv file as csv file itself, part 2

Hi, I have another problem. I want to sort another csv file by the first field. result.csv SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw /home/intannf/foto5/2015_0313_090651_219.JPG,0.,-7.77223,110.37310,30.75,996.46,148.75,180.94,182.00,63.92 ... (2 Replies)
Discussion started by: refrain
2 Replies

3. Shell Programming and Scripting

Save output of updated csv file as csv file itself

Hi, all I want to sort a csv file based on timestamp from oldest to newest and save the output as csv file itself. Here is an example of my csv file. test.csv SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0739.JPG,2015:02:17 11:32:21 /home/intannf/foto/IMG_0749.JPG,2015:02:17 11:37:28... (10 Replies)
Discussion started by: refrain
10 Replies

4. 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

5. Shell Programming and Scripting

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies

6. Shell Programming and Scripting

Edit csv file with bash

I' trying to use bash to edit a csv file from this format: "apples","oranges","grapes" "bread","butter","milk" To this: "apples oranges grapes" So that if I would open the csv file in open office, "apples oranges grapes" Would be in one single cell, and "bread (2 Replies)
Discussion started by: locoroco
2 Replies

7. Shell Programming and Scripting

2 problems: Mailing CSV file / parsing CSV for display

I have been trying to find a good solution for this seemingly simple task for 2 days, and I'm giving up and posting a thread. I hope someone can help me out! I'm on HPUX, using sqlplus, mailx, awk, have some other tools available, but can't install stuff that isn't already in place (without a... (6 Replies)
Discussion started by: soldstatic
6 Replies

8. Shell Programming and Scripting

How to edit particular cell of csv file using shell script

I have one csv file and in that I want update particular cell. I know the row and coloumn number for that respective. Please help me... (6 Replies)
Discussion started by: deepak_p86
6 Replies

9. Shell Programming and Scripting

Need to compare two csv files values and write into another csv file

Hi all, Am new to scripting. So i just need your ideas to help me out. Here goes my requirement. I have two csv files 1.csv 2.csv abc,1.24 abc,1 def,2.13 def,1 I need to compare the first column of 1.csv with 2.csv and if matches then need to compare... (2 Replies)
Discussion started by: chinnahyd
2 Replies
Login or Register to Ask a Question