Solved Remove Double quotes for Empty data values

December 18, 2016 at 19:31:21
Specs: Windows 7
Hi,

I am trying to remove double quotes for null attributes from a particular test.dat file.

Input

123|"Mathew"|"|"1980-01-01"|"
421|"|"|"|"

Output

123|"Mathew"| |"1980-01-01"|
421| || |


I tried modifying existing code which I found online, but I am getting the parse error and the script is removing all the double quotes, how can I mention that double quotes should be removed only when the field value is empty.

# Script ReplaceDoubleQuotes.txt
var str content
cat "test.dat" > $content
while ( { sen "^\"^" $content } > 0 )
sal "^\"^" "" $content > null
echo $content > "test.dat"


Thank You,
Pranathi


See More: Remove Double quotes for Empty data values

Report •

#1
December 19, 2016 at 06:45:29
If this:
421|"|"|"|"
becomes:
421| || |
Why do the 1st & 3rd removals leave a space but not the 2nd & 4th?

21:45 2016-12-19

=====================

M2 Get custom script or take private lessons


Report •

#2
December 19, 2016 at 18:10:40
Sorry for the confusion,I was testing a script to achieve and copied the output. I was replacing with empty values on particular Fields,

I am trying to achieve the output as below

421|"|"|"|"
becomes:
421||||


Report •

#3
December 19, 2016 at 20:58:53
✔ Best Answer
::====== script starts here ===============
::
:: p3.bat 2016-12-20 10:24:50.93
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

:main
for /f "tokens=* delims= " %%a in (myfile) do (
set S=%%a
set S=!S:^|^"^|=^|^|!
set S=!S:^|^"^|=^|^|!
set L=!S:~-1!
if '!L!' equ '^"' set S=!S:~0,-1!
echo.!S!
) >> NEWFILE
goto :eof
::====== script ends here =================

=====================

M2 Get custom script or take private lessons


Report •

Related Solutions

#4
December 20, 2016 at 17:27:15
M2G, I think it's supposed to be a bash script? At least that's how it looks to me when looking at the code snippet provided.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)


Report •

#5
December 20, 2016 at 22:44:41
Rain,

Hard tellin' not knowin'.

But his spec is win7

BTW

Is this a question:

"I think it's supposed to be a bash script?"

=====================

M2 Get custom script or take private lessons


Report •

Ask Question