Changing a CSV file in Korn shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing a CSV file in Korn shell
# 1  
Old 02-27-2006
Changing a CSV file in Korn shell

Hi All,

Please can someone help me how I can read a CSV file with 10 columns and remove the 2nd, 4th, 6th, 8th column and build the new output file. Script to be done in Korn shell.

File contains data like bnt, lb2, lb3, vnw, lb4, lb5, bst, lb6, lb7, vgw (multiple rows)

Output file should contain bnt, lb3, lb4, bst, lb7, vgw (multiple rows)

Thanks in advance.

-RiM

Last edited by riteshm; 02-27-2006 at 12:39 PM.. Reason: for clear understanding of the requirement
# 2  
Old 02-27-2006
Try this

awk -F "," '{for(i=1;i<=NF;i++) if(i!=2 && i!=4 && i!=6 && i!=8) if(i<NF) printf("%s,",$i); else printf("%s%s",$i,"\n");}' <filename>
# 3  
Old 02-27-2006
cut -d, -f1,3,5,7,9- file1 > file2
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

2. Shell Programming and Scripting

Changing date format in CSV file

I have a CSV file with a date format like this; 11/19/2012 17:37:00,1.372,121.6 11/19/2012 17:38:00,0.743,121.6 Want to change the time stamp to seconds after 1970 so I can get the data in rrdtool. For anyone interested, this is data from a TED5000 unit and is Kwatts and volts. Needs to... (3 Replies)
Discussion started by: ottsm
3 Replies

3. Shell Programming and Scripting

Changing dates in a csv file

Hello, Is there a script template out there that will assist me on creating a script to search for dates with "2011" and change it to "2012" in an excel spreadsheet. I am in Ksh :confused: Thank you, Bryan (1 Reply)
Discussion started by: BrutalBryan
1 Replies

4. Shell Programming and Scripting

Korn shell program to parse CSV text file and insert values into Oracle database

Enclosed is comma separated text file. I need to write a korn shell program that will parse the text file and insert the values into Oracle database. I need to write the korn shell program on Red Hat Enterprise Linux server. Oracle database is 10g. (15 Replies)
Discussion started by: shellguy
15 Replies

5. Shell Programming and Scripting

changing csv file contents to file of rows

i have a file a.txt contents as 1,2,3,4,......etc...in a single line, i want to write to another file in rows as 1 2 3 4 5 can u help? i do not know the length of a.txt (4 Replies)
Discussion started by: pravfraz
4 Replies

6. Shell Programming and Scripting

changing the format of CSV file

Hi Experts, Please help me to get the following from script for Unix ENvironment(shell, perl, tr, sed, awk). INPUT FILE: 20K,ME,592971 20K,YOU,2 20K,HE,1244998 50K,YOU,480110 50K,ME,17 50K,HIS,10 50K,HE,1370391 OUTPUT FILE: K,ME,YOU,HE,HIS 20K,592971,2,1244998,0... (5 Replies)
Discussion started by: ashis.tewari
5 Replies

7. UNIX for Dummies Questions & Answers

korn shell script to keep history of same file

Hello, How do I write a korn shell that will rename file with the current date. What I want to do is, I have a file that is re-written every day. But instead, I want to keep a 14 day history of the file. So I want to write a script that will rename the current file with a date attached to the... (2 Replies)
Discussion started by: watson2000
2 Replies

8. Shell Programming and Scripting

Read file - korn shell

Hello!! I'm want to read each line of a file. I'm doing a cut command, using \n - linefeed as delimeter and "list" as my file. cut -f1 -d"\n" -s < list Changing the file, putting spaces and doing cut -f1 -d" " -s < list it works, but with linefeed nothing is returned. Thanks... (5 Replies)
Discussion started by: alienET
5 Replies

9. UNIX for Dummies Questions & Answers

file activity (open/closed) file descriptor info using KORN shell scripting

I am trying to find a way to check the current status of a file. Such as some cron job processes are dependent on the completion of others. if a file is currently being accessed / modified or simply open state I will wait until it is done being processed before attempting the next process on that... (3 Replies)
Discussion started by: Gary Dunn
3 Replies

10. UNIX for Dummies Questions & Answers

Changing korn shell script text Menu colors?

Is it possible to change the color of text in a korn shell script Menu? I can change the color of session text through my telnet client but I want to be able to change color text in the Korn shell menu to highlight certain items. (6 Replies)
Discussion started by: darthur
6 Replies
Login or Register to Ask a Question