csv file editing using KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting csv file editing using KSH
# 1  
Old 05-04-2011
csv file editing using KSH

I'm trying to write a shell script to extract useful fields in a csv file and copy them to a new file:

the input file is as below when opened using notepad++:
Code:
////////////////////////////////////////////////////////////
ZZZZZZZZZZZZZZZZZZZZZZ
 ,"A", , , ,24,18,0,0,42,0
 , ,B, , ,0,16,0,0,16,0
 , , ,C, ,0,16,0,0,16,0
 , , , ,D,0,16,0,0,16,0
 , ,E, , ,18,0,0,0,18,0
 , , ,F, ,18,0,0,0,18,0
 , , , ,G,18,0,0,0,18,0
 , ,H, , ,0,2,0,0,2,0
 , , ,I, ,0,2,0,0,2,0
 , , , ,J,0,2,0,0,2,0
 , ,K, , ,6,0,0,0,6,0
 , , ,L, ,6,0,0,0,6,0
 , , , ,"M",6,0,0,0,6,0
 ,"N", , , ,0,40,0,0,40,0
//////////////////////////////////////

the result file after processing should be:

,"A",42
,"N",40

note that the "M" record has not been extracted since it doesn't start after the first ,

Thanks

Last edited by pludi; 05-04-2011 at 08:06 AM..
# 2  
Old 05-04-2011
Code:
awk -F, '$2 ~ /^".*"$/ {print FS $2 FS $(NF-1)}' infile > newfile; cat newfile
,"A",42
,"N",40

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Csv file editing

Help me, I have a csv file with following fields: sim name1 name2 name3 name4 name5 count file1 0.1 0.2 0.3 0.4 0.5 file2 0.1 0.2 0.3 0.4 0.5 file3 0.1 0.2 0.3 0.4 0.5 file4 0.1 0.2 0.3 0.4 0.5 ... (6 Replies)
Discussion started by: vinnu0154
6 Replies

2. Shell Programming and Scripting

ksh - Read input from file and output CSV i same row

Hello I have the following output and want the output to look: FROM: GigabitEthernet0/0 is up, line protocol is up 1 input errors, 0 CRC, 0 frame, 1 overrun, 0 ignored 275 output errors, 0 collisions, 3 interface resets GigabitEthernet0/1 is up, line protocol is up 0... (4 Replies)
Discussion started by: JayJay2018
4 Replies

3. Shell Programming and Scripting

ksh CSV to XML file (noob tier)

Hey all, I'm very new to shell scripting and would love some help. I have been messing around with KSH at my job, and have been tasked with generating an XML file from multiple CSV files. However, I barely even understand the syntax for for loops! Output should be something along the lines of ... (2 Replies)
Discussion started by: Parrakarry
2 Replies

4. Shell Programming and Scripting

Compare 2 csv files in ksh and o/p the difference in a new csv file

(say) I have 2 csv files - file1.csv & file2.csv as mentioned below: file1.csv ID,version,cost 1000,1,30 2000,2,40 3000,3,50 4000,4,60 file2.csv ID,version,cost 1000,1,30 2000,2,45 3000,4,55 6000,5,70 The... (7 Replies)
Discussion started by: Naresh101
7 Replies

5. Shell Programming and Scripting

Editing crontab via ksh

Hi all, I am trying the following I am hoping that the crontab would be changed. but it prints the previous crontab and says Can anyone tell me the correct ksh command that should be used here? I don't want to edit the crontab with crontab -e, I need to edit it via ksh. Thank... (2 Replies)
Discussion started by: ajaba
2 Replies

6. Shell Programming and Scripting

create csv in ksh from tricky log file

hi guys, trying to create a csv from a tricky log file in ksh, using 'awk '{print $1" "$14" "$15" "$16" "$17" "$18" "$19}' >> $TMP_FILE' on another set of files I have an output file with hundreds of lines in which looks like so: ABC_DEFGHI_16_JKLMNP11.20101115_095412_374.log:09:54:29.579... (3 Replies)
Discussion started by: rich@ardz
3 Replies

7. Shell Programming and Scripting

Assign field value in a .csv file to a variable using ksh

Hi, I'm new to the scripting world... I want to know that how can I assign the the field value(that has multiple lines) of a .csv file to a variable??? Model of my .csv file : 1 Poppy 5 2 red 6 3 black 5 4 white 8 and so on,the list... (4 Replies)
Discussion started by: srim
4 Replies

8. Shell Programming and Scripting

ksh script to create a generic csv file from different source formats

Hi all, I have a requirement to create a "superset" file out of a number of different sources with some different and some same columns. We intend to have a manually updateable SuperSetCols.csv which would look like "ColA","ColB","ColC","ColD","ColE","ColF","ColG" so someday we may add... (3 Replies)
Discussion started by: Leedor
3 Replies

9. Shell Programming and Scripting

Editing a ksh script > Please assist!

I am trying to edit a script that contains the following: /DBA/general/sh/rman_backup.ksh -d PROD2 -l 1 I am trying to add a logic in the script such that if /DBA/general/sh/rman_backup.ksh does not exists, then the script would return an error code of 1. Otherwise, the script continues... (4 Replies)
Discussion started by: ora_umair
4 Replies

10. Shell Programming and Scripting

Editing file during running ksh in HP failed

Hi falks, I have the following program: #!/bin/ksh ed -s /home/ias/v9.0.3/j2ee/OC4J_RiGHTv_HPCD2/applications/Xbip/Xbip/WEB -INF/config/application.properties <<EOF >/dev/null 1 d . d . a application.filePath.core = /core-HPCD2/Html/ application.filePath.xbip =... (2 Replies)
Discussion started by: nir_s
2 Replies
Login or Register to Ask a Question