Replace delimited value with specific conditions

Hi Team,

We have requirement , we are trying to load the txt format file via sqlloader, we are facing issue like double quotes " are falling inside the value . so sqlloader fails to load the file. so we have the option to implement to load the file. the following replace option need to be perfomed in the file.

Input file

"11471726"~"ASDFSA"DF"
"9446318"~"IKLJSDFSA"
"6957905"~"ASFSDFL"LIEHS"
"30201774"~"ASFDSAFDS"

O/p Needed

^11471726^~^ASDFSA�DF^
^9446318^~^IKLJSDFSA^
^6957905^~^ASFSDFL�LIEHS^
^30201774^~^ASFDSAFDS^

Thanks in advance.

Hi, try:

awk '{for(i=1; i<=NF; i++) {gsub(/^"|"$/,"^",$i); gsub(/"/,"�",$i)}}1'  FS=\~ OFS=\~ file

Hi, Thanks for your quick respod.
when i try to execute the command. it is showing syntax error

-ksh: syntax error: `)' unexpected

It works perfectly (producing the exact sample output you requested) when I try it using ksh on macOS 10.12.6.

You should always tell us what operating system and shell you're using when you open a thread in this forum so we know what capabilities your system has. If you're using a Solaris/SunOS system, change awk in the suggestion Scrutinizer posted to /usr/xpg4/bin/awk or nawk .

If you're using some other OS, please verify that you copied Scrutinizer's suggestion exactly. One might expect an error like the one you showed us from ksh if one or both of the single-quotes ( ' ) in his suggestion had been replaced with back-quotes ( ` ).

Sorry for didn't mention in OS version.
the below version we are using .
Red Hat Enterprise Linux Server release 6.8 (Santiago)

Kindly help us to accomodate the query with above versions.

Show us exactly what command you used (in CODE tags).

The below code, i have tried to execute in putty.

awk '{for(i=1; i<=NF; i++) {gsub(/^"|"$/,"^",$i); gsub(/"/,"�",$i)}}1'  FS=\~ OFS=\~  file.txt

To keep the forums high quality for all users, please take the time to format your posts correctly.

Use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Continued refusal to properly format your posts may result in your account being placed in read-only mode for a while, or in you being banned from using this forum.

The code Scrutinizer suggested should work on a correctly functioning awk , but GNU awk sometimes handles regular expressions slightly differently than the way they are specified in the standards. But, the error you are getting is coming from the Korn shell; not from awk and mismatched double-quotes inside a single-quoted string in a shell script should have absolutely no effect on the number of parentheses that the shell sees as shell operators (i.e., none).

Although, in theory, it shouldn't make any difference, please try the following slight modifications of Scrutinizer's suggestion:

awk '{for(i=1; i<=NF; i++) {gsub(/^["]|["]$/,"^",$i); gsub(/["]/,"�",$i)}}1'  FS=\~ OFS=\~  file.txt

and:

awk '{for(i=1; i<=NF; i++) {gsub(/^\"|\"$/,"^",$i); gsub(/\"/,"�",$i)}}1'  FS=\~ OFS=\~  file.txt

and let us know if either of these produce different results.

Hi ,

It working fine. last character of double quotes are converted in to �. we need only double dollar are falling in value not at the end of the line. if double quotes falls first and last of every line . it should be ^.

We may have a language barrier here. What does "double dollar are falling in value" mean?

Please show us which awk command you are using, the sample input you are using, and the output you are getting. If you are trying to convert dollar signs ( $ ) as well as double-quotes ( " ) please explain under what circumstances that should happen. I didn't see anything about changing dollar signs in your earlier posts.