Update a CSV file with a predetermined value


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Update a CSV file with a predetermined value
# 1  
Old 08-02-2011
Update a CSV file with a predetermined value

Hi All
Thanks for all your post and advice, you have been extremely helpful in the past.


I have an issue where I'm stumped and am seeking a wider opinion.

I'm relatively new to unix and have been tasked with collating a vast amount of data and presenting it within excel.

Now the original data from the unix boxes are csv files, but I have to update these files dependent on an entry in the first field.

ie:

Field one is a path

Field to be updated depends on the contents of field pne.

Filed one path would look like:

/usr/home
/adm/user
/opt/oracle

so depending on the path i require a script that would put a predetermined vaule in the updated field.

Field one Filed updated
/usr/home owner is Team1
/adm/user owner is Team2
/opt/oracle owner is Team3


The above is what I'm trying to achieve, whereby the script reads through each line of data and depending on the path will update a new field.

Hope this is clear and thanks for any assistance.
# 2  
Old 08-02-2011
Code:
sed 's!/usr/home!& owner is Team1!' infile

You can do the same with the other patterns (paths). Just redirect the output to a new file or check if your sed has the -i option so you it edits the file right in place.
# 3  
Old 08-02-2011
Many thanks Zaxxon for the prompt response.

Would this allow for multiple lines to be updated to the same file?
# 4  
Old 08-02-2011
Yes, you can try it out. For the other 2 paths and 2 teams you have to use a similar line or expand the existing sed command.
# 5  
Old 08-02-2011
still stumped here Smilie

---------- Post updated at 03:19 PM ---------- Previous update was at 03:10 PM ----------

sorry typo..., that works a charm

moving on a step, how do i put this new input at the end of the line? there are six commas per line??
# 6  
Old 08-03-2011
Quote:
how do i put this new input at the end of the line? there are six commas per line??
? Please give an example snippet of the input and desired output using code tags.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

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

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

4. Shell Programming and Scripting

Update field value on a csv file

Hi I have a job status csv file. I want to update the status of the job in the file. Below is the csv file 1,jobname1,in_progress,starttime,somthing,somthing 2,jobname2,completed,starttime,somthing,somthing 3,jobname3,failed,starttime,somthing,somthing... (8 Replies)
Discussion started by: midhun19
8 Replies

5. Shell Programming and Scripting

Update the table using values from a csv file

i want to run update query for oracle which is in up.sql taking values from a.csv. I have implemented shell script to do it. extn="perl" ls -1 | while read file do echo "$file,$extn" > a.csv done up.sql contains update file_list set filename=$1 where extn=$2; The code to update is... (2 Replies)
Discussion started by: millan
2 Replies

6. Shell Programming and Scripting

how to update a .csv file?

Hi everyone, im a newbie so plz bare with me, i have this txt file which contains an output of a query from oracle. now i copied the string inside this txt file in a .csv file. i used this command in doing this process: echo "Fatal alerts:", $(cat a.txt) > test.csv now what i want to... (1 Reply)
Discussion started by: 4dirk1
1 Replies

7. Shell Programming and Scripting

Command to create and update csv file

Hi, I need to create a csv file to store oracle query output. This report need to be created on hourly basis. The csv file report format as "Report_22_Sep_09_13IST.csv". I have the oracle query. Now i need to create and move the oracle query output to the report row by row starting from 3rd row.... (6 Replies)
Discussion started by: Sekar1
6 Replies

8. Shell Programming and Scripting

Update a column value in csv files

Hi all I am new to scripting and i have an application from which i will export into a csv file as follows Column1, Column2, Column3 Sno1, Folder\Test.txt, Fail Sno2, Folder\Test1.txt, Pass Sno3, Folder\Test2.txt, Fail Now i need to change the column2 in all the rows from "Folder\" ... (1 Reply)
Discussion started by: rajeshrp
1 Replies

9. UNIX and Linux Applications

Mounting a USB device with a predetermined name

When I attach a USB storage device to my Solaris server, the mount point is coming up as /rmdisk/unnamed_rmdisk Is there anyway I can have this device come up as a mounted device with a predetermined mount name eg /morespace rather than unnamed_rmdisk ? (0 Replies)
Discussion started by: jimthompson
0 Replies
Login or Register to Ask a Question