![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| insert multiple lines into a file | c0mrade | Shell Programming and Scripting | 12 | 09-04-2008 04:04 PM |
| parsing error in if statement | rakeshou | Shell Programming and Scripting | 2 | 09-25-2007 10:46 AM |
| How to insert tab at specified column.HELP | sslr | UNIX for Dummies Questions & Answers | 7 | 09-21-2007 10:54 AM |
| Insert TAB in echo statement | sunils27 | Shell Programming and Scripting | 5 | 08-26-2005 03:36 AM |
| awk command for INSERT statement | nattynatty | Shell Programming and Scripting | 4 | 05-10-2002 02:11 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
(sed) parsing insert statement column that crosses multiple lines
I have a file with a set of insert statements some of which have a single column value that crosses multiple lines causing the statement to fail in sql*plue. Can someone help me with a sed script to replace the new lines with chr(10)?
here is an example: insert into mytable(id, field1, field2) values ('1', 'myvarchar', 'my varchar that has carriage returns, and is making my script die'); insert into mytable(id, field1, field2) values ('2', 'myvarchar2', 'my varchar that has carriage returns, and is making my script die. This one is even trickier because it contains a quote that I didn't expect. '); Note that the value for field2 (third column) crosses multiple lines. The first case I would need to replace each new line with: ' || chr(10) and the start of the following line with: ||' resulting in: insert into mytable(id, field1, field2) values ('1', 'myvarchar', 'my varchar '||chr(10)||'that has carriage '|| chr(10) ||'returns, and is making '|| chr(10) ||' my script die'); In the second case I would need to do the same as the first case with the following addtions. 1. I need to handle the single quote by using ''' 2. because the last line doesn't have any text I can replace the last carriage return with '||chr(10) resulting in: insert into mytable(id, field1, field2) values ('2', 'myvarchar2', 'my varchar '||chr(10)|| 'that has carriage returns, and is making '||chr(10)||'my script die. This one is even trickier because '||chr(10)||'it contains a quote that I didn't expect.'); This has really stumped me and I am hoping there are some guru's out there that can help me out. So far I have come up with this script that prints the lines that I want to process: /,.*'[^';]*$/p The way I read it is search for a "," followed by 0 or more characters (I wanted just whitespace but \s doesn't work) followed by a single quote and 0 or more characters but not ' ; before the end of the line. Put simply, a single quote optional characters but not the end quote nor end statement before the end of the line. So I expect that this finds the start of patterns like in the case #1 now I need to find the end of the pattern and process the chunk like I mentioned above. Anyway, I'd really appreciate some help. T.I.A. JJ |
|
||||
|
awk and how to use <'> in awk
Hi,
Hope can help me. Actually, i do not know how to use single quote<'> in awk. So i use <"> insteand of <'> and the output is ok. If anyone know how to use single quote<'> in awk, pls kindly inform me. Thanks in advanced. Output: Code:
insert into mytable(id, field1, field2)
values ('1', 'myvarchar', 'my varchar"||chr(10)
||"that has carriage returns, and is making "||chr(10)
||"my script die');
insert into mytable(id, field1, field2)
values ('2', 'myvarchar2', 'my varchar"||chr(10)
||"that has carriage returns, and is making "||chr(10)
||"my script die. This one is even trickier because "||chr(10)
||"it contains a quote that I didn't expect."||chr(10)
||"');
Code:
awk '
{
if (index($0,"values")!=0)
n=1;
if (index($0,");")!=0)
n=3
if(n==1)
{
print $0"\"||chr(10)"
n=2
}
else if(n==2)
print "||\""$0"\"||chr(10)"
else if (n==3)
{
print "||\""$0
n=0
}
else
print $0
}' filename
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|