Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Need to remove "-" from text files before uploading.


  • Please log in to reply

#1
magusbuckley

magusbuckley

    Member

  • Member
  • PipPipPip
  • 626 posts
Hello:

I'm in the IT department for a casino. For those of you not in the gaming industry, there is a group of people called The Count Team who collect the money from the slot machines in the middle of the night. They feed the money into a money sorter and send a file, containing information about the money and which machines it all came from, to a PC. From there, the file is uploaded to an AS/400 machine.

For some reason, when the file comes across from the money counter, the text file containing all the data will at times put a minus sign in front of the asset numbers of some of the slot machines. When they try to upload those files, the AS/400 program that we use doesn't know what to do with it. In short, it creates a huge mess.

Is there a way I can create a batch file that will remove all of the minus signs from the text document before they upload?

Thanks,

Magus
  • 0

Advertisements


#2
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP
All you want it to do is remove every minus sign from the entire document?

Use a real scripting language like Python or Perl or PHP.
In PHP for example:
$data = file_get_contents("yourfile.txt");
$data = str_replace("-", "", $data);
file_put_contents("yourfile.txt", $data);

or if you are in a unix-like environment (or you have sensible unix tools installed in Windows), you can do this from the command-line with 'sed' (Stream EDitor):

sed -e "s/-//g" yourfile.txt >> your_replaced_file.txt

and this line of code could obviously be tossed in a batch file. You just need sed installed.


EDIT: you sure the minus signs don't mean anything? You sure you want to discard that information? Maybe they mean that particular slot machine is net negative on the night. As in, it has lost more money than it has taken in.

Edited by Swandog46, 03 December 2007 - 04:56 AM.

  • 0

#3
magusbuckley

magusbuckley

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 626 posts
The PHP code looks simple enough. I took Q-Basic, RPG, and COBOL in college about 10 years ago. Do I have to buy a PHP program and compile the code?

Thanks,

Magus
  • 0

#4
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP
PHP is free (open-source). Get it here:
http://www.php.net

This is a script (interpreted code), it does not get "compiled" natively ahead of run-time, which is why you need the PHP interpreter running in order to execute a script. At run-time the interpreter parses the code, compiles it on the spot into byte code, and executes that byte code. This is why interpreted languages are ~10x slower than native compiled languages.

But I feel compelled to ask again: are you really sure these minus signs are so meaningless that you want to discard them?

Edited by Swandog46, 04 December 2007 - 06:03 AM.

  • 0

#5
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
I wrote a little script that you could use as another option. It's not as compact as the other options, but should work great on the command line or in batch.

Usage: cscript replace.vbs file findstring [replacestring=""]

Example: cscript replace.vbs C:\Test\Text.txt "-"

The script will output a new file called "C:\Test\Edited_Text.txt".

Let me know if you have any problems with it or would like any changes made.

Ax

Attached Files


  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP