Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed replacement between characters

Status
Not open for further replies.

tballs

Technical User
Jul 27, 2011
4
Howdy... new to sed/awk scripting so hopefully I can get some assistance here.

I have multiple lines of data in a file that are comma delimited. Here is an example:

Advantage 12,5650,01/03/2011,Refinancing,4.24,144,"Conventional (Any loan other than GHA, VA, FSA, or RHS loans)","$137,300.00 ",Owner-occupied as a prin
cipal dwelling

I initially thought I would use awk to reformat into a useful data file for input into other software. In doing so I would use the comma's. However, There are commas in between the quotes(i.e. "$137,300.00 ") that is messing with my script.
How can I remove just the comma's that reside between the quotation marks?
 
Here is a solution to a similar problem that I posted a few years ago:

awk -F'"' -v OFS='"' '{ for (i=2;i<NF;i+=2) { gsub(","," ",$i) }; print }'
Code:
awk -F'[red]"[/red][purple]' -v OFS='[/purple][red]"[/red]' '{ [olive]for[/olive] (i=2;i<[blue]NF[/blue];i+=2) { [b]gsub[/b]([red]"[/red][purple],[/purple][red]"[/red],[red]"[/red][purple] [/purple][red]"[/red],[blue]$i[/blue]) }; [b]print[/b] }' inputfile.csv >outputfile.csv


Annihilannic.
 
olded, thanks for your response.
I attempted to get that example to work. I just left it as is so it would changed the , to a - but didn't have any luck. Here is what I had with results. This is way over my head in regards to understanding what each character is doing (or what it causes the script to do). So, I'm not sure where in that line it's having a problem.

speclive:LIVE $ more sedscrpt
:loop
s/^((([^"]*"){2})*[^"]*"[^",]*),/\1-/
t loop
speclive:LIVE $ sed -f sedscrpt HMDA>HMDA3
sed: Function s/^((([^"]*"){2})*[^"]*"[^",]*),/\1-/ cannot be parsed.
speclive:LIVE $
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top