View unanswered posts | View active topics It is currently 22 Sep 2014 18:18



Post new topic Reply to topic  [ 2 posts ] 
use batch file to insert string "NULL" .. 
Author Message

Joined: 14 Jun 2012 02:45
Posts: 3
Post use batch file to insert string "NULL" ..
Basically i need to fill in some string on column that is NULL.. just insert NULL(string)

here is the scenario

input.txt
Code:

field1      field2           field3
AAAA        BBBB             CCCC
DDDD                                 
EEEE        FFFF                 
GGGG                         HHHH     



Those empty one shall put a NULL inside
something like this,,

output.txt
Code:

field1      field2           field3
AAAA        BBBB             CCCC
DDDD        NULL             NULL                           
EEEE        FFFF             NULL     
GGGG        NULL             HHHH     


## take note the field2 and field 3 space is different.. field 1 is almost with content hence the script just has to tackle field 2,3
My approach is to count the character until field 2 (12character from left) then check if is empty insert NULL. Then continue for field 3 (29 character from left) check if is empty insert null
Code:
@echo off
set line =
for /F in(input.txt) do
if "!line :~ 12" eq " " do
write null     (i not sure whether is correct)
if "!line:~ 29 " eq " " do
write null   
echo  > output.txt


Would appreciate if anyone can guide me on this..
thanks


14 Jun 2012 03:14
Profile

Joined: 10 Feb 2012 02:20
Posts: 4194
Post Re: use batch file to insert string "NULL" ..
This assumes the strings are fixed lengths with every line padded with spaces.

Edited:

Code:
@echo off
setlocal enabledelayedexpansion
for /F "delims=" %%a in (input.txt) do (
set "line=%%a"
if "!line:~0,1!"==" " set "line=NULL!Line:~4!"
if "!line:~13,1!"==" " set "line=!line:~0,12!NULL!Line:~16!"
if "!line:~30,1!"==" " set "line=!line:~0,29!NULL"
echo >>"output.txt" !line!
)


15 Jun 2012 01:07
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.