Not able to convert the second column to required format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to convert the second column to required format
# 1  
Old 12-31-2012
Not able to convert the second column to required format

I have this file

Code:
103,7243534512111,NiaC1-02
105,720412845543550,NiaC2-00
105,720439254543351,NiaC200
105,720445724354315,Nia100
105,72044770454398,Nia100
105,720484154334546,Nia616

i want in this format


Code:
insert into aildump values(103,'7243534512111','NiaC1-02');


I'm able to do until this part

Code:
insert into airteldump values (103,7243534512111,NiaC1-02)

with this sed script

Code:
Code:
sed -e 's/^/(/g' -e 's/$/)/g' sed -e 's/^/insert into airteldump values /g' dbconv.txt


but i'm not getting the second and third column in single quotes i.e

Code:
insert into aildump values(103,'7243534512111','NiaC1-02');


instead m getting

Code:
insert into airteldump values (103,7243534512111,NiaC1-02)

plz help

Last edited by Scrutinizer; 12-31-2012 at 04:16 AM..
# 2  
Old 12-31-2012
Code:
  $ awk 'BEGIN{FS=OFS=","}
{print "insert into aildump values("$1,"**"$2"**","**"$3"**)"}' file | sed "s/\*\*/\'/g"
insert into aildump values(103,'7243534512111','NiaC1-02')
insert into aildump values(105,'720412845543550','NiaC2-00')
insert into aildump values(105,'720439254543351','NiaC200')
insert into aildump values(105,'720445724354315','Nia100')
insert into aildump values(105,'72044770454398','Nia100')
insert into aildump values(105,'720484154334546','Nia616')

This User Gave Thanks to pamu For This Post:
# 3  
Old 12-31-2012
open the file in excel write format of shells..it is simple..
# 4  
Old 12-31-2012
Code:
sed "s/\(.*\),\(.*\),\(.*\)/insert into aildump values(\1,'\2','\3');/" infile

Code:
awk -F, '{printf s,$1,$2,$3}' s="insert into aildump values(%s,'%s','%s');\n" infile

These 2 Users Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert rows to column and print output in required format

Hi All, i am trying to print the solaris 11 packages in below required format, But i am unable to do that. Current ouput : root@abc# pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' NAME: QLogic 570x/571x Gigabit Ethernet Driver VERSION: 11.11,REV=2009.11.11 ... (7 Replies)
Discussion started by: balu1234
7 Replies

2. Shell Programming and Scripting

Need help to format one txt file to required format

Hello Everyone, I have one source file which is genarated by SAP in different format(Which I've never seen). I need to convert that file to required format and I need to read this target file from Datastage to use this in my Jobs. So I do not have any other options except to use Unix script to... (4 Replies)
Discussion started by: Prathyu
4 Replies

3. Shell Programming and Scripting

Convert date column as yyyy/mm/dd format

Hi All, I have file like April 10, 2013,raj April 29, 2013,raj1 Output : 2013/04/10,raj 2013/04/29,raj1 Please help me how to do... (9 Replies)
Discussion started by: bmk
9 Replies

4. Shell Programming and Scripting

perl module to convert xlsx format to xls format

Hi Folks, I have written a perl script that reads data from excel sheet(.xls) using Spreadsheet::ParseExcel module. But the problem is this module doesn't work for excel sheets with extension .xlsx. I have gone through Spreadsheet::XLSX module with which we can read from .xlsx file directly.... (1 Reply)
Discussion started by: giridhar276
1 Replies

5. Shell Programming and Scripting

Convert the date format from mdy to ymd in column of file

The date format in the delimited file for one column '6/27/2011 12:00:00 AM' Is it possible o change it to '2011-06-27 12:00:00 AM' for all the records.. Thanks in advance..... (8 Replies)
Discussion started by: infernalhell
8 Replies

6. Shell Programming and Scripting

Convert comma text file to Column in html format

I am trying to generate a report with below file : File1 : EQADM,edrtere9-phys,8122caef0,gpatmon,/bin/ksh,nuten Erick EQADM,edrtere11-phys,8227caef0,gpatmon,/bin/ksh,nuten Erick EQADM,edrtere3-phys,822caef0,gpatmon,/bin/ksh,nuten Erick can you help me convert it to html and add... (9 Replies)
Discussion started by: sriram003
9 Replies

7. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like ..ݡ.ݡ ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

8. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

9. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

10. Shell Programming and Scripting

convert mmddyy date format to ccyyddd format??

hi, for reading a cobol indexed file i need to convert "mmddyy" date format to "ccyyddd" format. i checked the datecalc and other scripts but couldnt modify them to cater to my need:(... The datecalc gives an output which i believe is the total days till that date, but i want to convert it... (2 Replies)
Discussion started by: Bhups
2 Replies
Login or Register to Ask a Question