DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Shell Scripting (http://www.daniweb.com/forums/forum113.html)
-   -   Windows batch script (http://www.daniweb.com/forums/thread200334.html)

codester Jun 28th, 2009 7:16 pm
Windows batch script
 
I'm new at scripting and I need help with converting multiple ".TXT" files to one ".CSV" file. Each file will have a different number of lines, then after the last line there is a blank line then more data, I don't want to use the data after the blank line. I need help with this today if possible.
The contents are as follows.

AAAUSA-0046 AAAA Functional Aggregate AAAAA061,100.00,0.00,0.00,good
AAAUSA-0057 AAAA CCCC - AAAAA026 - Functional Aggregate,100.00,0.00,0.00,good

Each line starts with the AAAUSA-nnnn, I need to have this in the first field of the CSV file. The second field in both lines will be different titles and some will include special characters.
The third field will be the "AAAAA061" .
The fourth will be the 100.00.

The "AAAAA061" and "AAAAA026" may be before or after the "Functional Aggregate", This isn't a big concern since I want to eliminate "Functional Aggregate".
Next I want to eliminate the commas and keep only the 100.00.
The output should look like this: for each row.
AAAUSA-0046 AAAAA AAAAA061 100.00

Field-1 = AAAUSA-0046
Field2 = AAAAA ( this could be multiple words with commas, dashes and spaces etc.)
Field3 = AAAAA061
Field4 = 100.00

Thanks in advance.

Ancient Dragon Jun 28th, 2009 7:53 pm
Re: Windows batch script
 
Windows batch files isn't sophisticated enough to do all that. You will need to write a small program in one of the man programming languages such as C or C++.

Is this the output you want?
Quote:

AAAUSA-0046,AAAA,AAAAA061,100.00
AAAUSA-0057,AAAA CCCC -,AAAAA026,100.00
Press any key to continue . . .

codester Jun 28th, 2009 8:40 pm
Re: Windows batch script
 
I'll be running the script through a cygwin command shell, so couldn't this be done using regex expressions?

codester Jun 28th, 2009 8:49 pm
Re: Windows batch script
 
I need it with out the commas, so that it can be put into an XLS spread sheet.
AAAUSA-0046 AAAA AAAAA061 100.00
AAAUSA-0057 AAAA CCCC AAAAA026100.00
The "AAAA" or "AAAA CCCC" would be in the second sell of the spread sheet.

Cell A1 would contain - AAAUSA-0057
Cell A2 would contain - "AAAA" or "AAAA CCCC"
Cell A3 would contain - AAAAA026
Cell A4 would contain - 100.00

Ancient Dragon Jun 28th, 2009 8:51 pm
Re: Windows batch script
 
I don't know. But it only took me about 1/2 hour to write a C++ program, 70 line (including blank lines) that produced the output I posted. And it will run a whole lot quicker than doing that with a shell script.

Ancient Dragon Jun 28th, 2009 8:56 pm
Re: Windows batch script
 
>>I need it with out the commas, so that it can be put into an XLS spread sheet.

Quote:

"AAAUSA-0046" "AAAA" "AAAAA061" 100.00
"AAAUSA-0057" "AAAA CCCC" "AAAAA026" 100.00
Press any key to continue . . .

codester Jun 28th, 2009 9:18 pm
Re: Windows batch script
 
I doing this as a training exercise for work and was requested to do it as a script. How about power shell? I never worked with programs so I'm not sure how to do C or C++.

sknake Jun 28th, 2009 9:50 pm
Re: Windows batch script
 
If you're using cygwin then you're not doing a windows batch script, you're more than likely using bash, sh, tcsh, zsh, etc. What shell are you running in cygwin?

codester Jun 28th, 2009 10:24 pm
Re: Windows batch script
 
I'm using bash in cygwin, but It would be best to use a windows batch script if possible.

Ancient Dragon Jun 28th, 2009 11:03 pm
Re: Windows batch script
 
you can't do windows script in cygwin. why not this


All times are GMT -4. The time now is 2:26 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC