Windows batch script

Reply

Join Date: Jun 2009
Posts: 9
Reputation: codester is an unknown quantity at this point 
Solved Threads: 0
codester codester is offline Offline
Newbie Poster

Windows batch script

 
0
  #1
Jun 28th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Windows batch script

 
0
  #2
Jun 28th, 2009
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?
AAAUSA-0046,AAAA,AAAAA061,100.00
AAAUSA-0057,AAAA CCCC -,AAAAA026,100.00
Press any key to continue . . .
Last edited by Ancient Dragon; Jun 28th, 2009 at 8:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: codester is an unknown quantity at this point 
Solved Threads: 0
codester codester is offline Offline
Newbie Poster

Re: Windows batch script

 
0
  #3
Jun 28th, 2009
I'll be running the script through a cygwin command shell, so couldn't this be done using regex expressions?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: codester is an unknown quantity at this point 
Solved Threads: 0
codester codester is offline Offline
Newbie Poster

Re: Windows batch script

 
0
  #4
Jun 28th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Windows batch script

 
0
  #5
Jun 28th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Windows batch script

 
0
  #6
Jun 28th, 2009
>>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" "AAAAA026" 100.00
Press any key to continue . . .
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: codester is an unknown quantity at this point 
Solved Threads: 0
codester codester is offline Offline
Newbie Poster

Re: Windows batch script

 
0
  #7
Jun 28th, 2009
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++.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Windows batch script

 
0
  #8
Jun 28th, 2009
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?
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: codester is an unknown quantity at this point 
Solved Threads: 0
codester codester is offline Offline
Newbie Poster

Re: Windows batch script

 
0
  #9
Jun 28th, 2009
I'm using bash in cygwin, but It would be best to use a windows batch script if possible.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Windows batch script

 
0
  #10
Jun 28th, 2009
you can't do windows script in cygwin. why not this
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC