Convert Tab text file to Pipe Delimiter CSV file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Convert Tab text file to Pipe Delimiter CSV file

#1 Post by zagix » 21 Nov 2014 02:06

Hi,

I have tab delimited text file in that i want to change the 2nd field value and convert the tab/spaces to pipe delimted CSV file.
Now i have conversion list, if 1 in 2 field it will be converted to 101000011, if 3 then 101000033.

Is that possibe to achieve via batch file.

dot(.) for display of tab delimited, they are not in text file.
2xxxxxxxxx17 ...1........ xxxxxxxxxxxxxxxxxxxxxxxxxxxxx....0000029961104599xxxx1220J.....1PU1366512....000000071800002
2yyyyyyyyy17....3.........xxxxxxxxxxxxxxxxxxxxxxxx............0000021991104599xxxxY2014.....2180 00000.....016420000264313

Squashman
Expert
Posts: 4479
Joined: 23 Dec 2011 13:59

Re: Convert Tab text file to Pipe Delimiter CSV file

#2 Post by Squashman » 21 Nov 2014 07:26

You are probably going to need this.
viewtopic.php?f=3&t=5702

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Convert Tab text file to Pipe Delimiter CSV file

#3 Post by dbenham » 21 Nov 2014 07:44

Very simple (and fast) if you are willing to use something like JREPL.BAT, a hybrid JScript/batch utility that performs regular expression search and replace. It is pure script that will run on any Windows platform from XP onward.

Using a simple brute force, multi-step approach, this reads test.txt and writes new.csv:

Code: Select all

jrepl "\t" "|" /f test.txt | jrepl "^([^|]*\|)1\|" "$1101000011|" | jrepl "^([^|]*\|)3\|" "$1101000033|" /o new.csv

Using a sophisticated, single pass:

Code: Select all

jrepl "^([^\t]*)\t1\t@^([^\t]*)\t3\t@\t" "$2|101000011|@$4|101000033|@|" /t @ /f test.txt /o new.csv

You can have the output replace the original file if you change /O NEW.CSV to /O -


Dave Benham

zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Re: Convert Tab text file to Pipe Delimiter CSV file

#4 Post by zagix » 23 Nov 2014 04:51

Thanks Dave Benham its works perfectly.
Thankyou.

Post Reply