|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need a script to convert comma delimited files to semi colon delimited
Hi All, I need a unix script to convert .csv files to .skv files (changing a comma delimited file to a semi colon delimited file). I am a unix newbie and so don't know where to start. The script will be scheduled using cron and needs to convert each .csv file in a particular folder to a .skv equivalent and create a token in the folder to show completion as well as a log showing the number of files and records converted for auditing. Sample data ... before conversion Code:
27981,13,"0901"," ","B18975362",1,"C",17,"1"," "," "," " 24875,12,"0901"," ","B24578942",0,"F",17,"0"," "," "," " Sample data ... after conversion Code:
27981;13;0901;;B18975362;1;C;17;1;;;;^ 24875;12;0901;;B24578942;0;F;17;0;;;;^ Please note that the number of columns in each file to be converted could be different, but that each .skv should have the same number of columns as the source .csv example source & target folder: /test/conv Any help would be most appreciated |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
try.. Code:
sed 's/,/;/g; s/\"//g; s/$/;^/' file |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi Pamu,
Thanks for the suggestion ... as I mentioned I am a complete newbie and dont know how I would write the script at all. Please could you give me a more detailed example that I could test on my data? Many thanks |
|
#4
|
|||
|
|||
|
You can do sth like below... Code:
$ cat file 27981,13,"0901"," ","B18975362",1,"C",17,"1"," "," "," " 24875,12,"0901"," ","B24578942",0,"F",17,"0"," "," "," " $ sed 's/,/;/g; s/\"//g; s/$/;^/' file > out_file $ cat out_file 27981;13;0901; ;B18975362;1;C;17;1; ; ; ;^ 24875;12;0901; ;B24578942;0;F;17;0; ; ; ;^ Hope this helps you Regards, pamu |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Code:
awk 'NR%2{gsub(/,/,";")}1' RS=\" ORS= file |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to convert comma delimited file to tab separator | krupasindhu18 | Shell Programming and Scripting | 4 | 02-22-2012 09:24 AM |
| How to convert a space delimited file into a pipe delimited file using shellscript? | nithins007 | Shell Programming and Scripting | 7 | 09-25-2011 05:33 AM |
| Urgent! need help! how to convert this file into comma delimited format | natalie23 | UNIX for Advanced & Expert Users | 2 | 08-28-2009 04:39 AM |
| how to convert this file into comma delimited format | natalie23 | Shell Programming and Scripting | 1 | 08-28-2009 04:25 AM |
| Converting Tab delimited file to Comma delimited file in Unix | charan81 | Shell Programming and Scripting | 22 | 01-20-2006 08:24 AM |
|
|