Bash script
Jun 9 2010, 9:51 pm
By: rockz  

Jun 9 2010, 9:51 pm rockz Post #1

ᴄʜᴇᴇsᴇ ɪᴛ!

Okay. I want 2 programs:

The first:
Edit a text file full of characters like so:
abcd1234./

I want to detect the lower case letter, and put it inside brackets with its upper case counterpart:
[aA][bB][cC][dD]1234./

Someone recommended I do a bash script, however I have no idea how to do this. I can understand if-then statements (if the character is "a", insert "A", then insert "][", read next letter), but I don't even know where to start with reading and editing bytes in a file.

The second program is probably pointless, just something I'd like to do:

Open an image/text file, then count the number of colors in an image and how many times it is used. It would be editing a huge bitmap file (usually not over 2 megapixels, or 6 megabytes). What I'd like to happen is have the program read 3 bytes, then store it in a couter, read the next 3, and add to the counter if that color was used before.

The output would be in a txt file with a 3 byte color, then the number of pixels using that color.

I realize it's not efficient, nor is it ideal, but it's about all I can handle, and I can always leave my computer on for a few hours to let it process everything, since I know it's going to be super slow.

If there's a better way that doesn't involve something ridiculously convoluted, I'd like to know, and how to make it.



"Parliamentary inquiry, Mr. Chairman - do we have to call the Gentleman a gentleman if he's not one?"

Jun 9 2010, 9:55 pm NudeRaider Post #2

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

http://www.actool.net/files/actoolinstall_540.exe
Is a pretty powerful macro generator. It's able to handle strings, write and read files and even read colors of screen pixels.
Its syntax is pretty easy to learn if you know any programming language and each command has a pretty good help.
I haven't done much with it so I'm not sure how useful it is for your specific case, but it should be worth checking out.




Jun 9 2010, 11:56 pm BeeR_KeG Post #3



I've done a similar program to the first one using Intelx86 assembly during an exam last semester. It was pretty simple, we took each lower case letter and replaced it with an upper case letter and the upper case letters stayed the same. Using assembly will make it very easy, you'd just detect every character on the file and using the ASCII character values and a simple algorithm to detect and transform from binary to hexadecimal and you'd be set. For the second program, I believe the same idea can be used, but it could be a bit more complex since I haven't worked with picture files for assembly.

If you have DOS knowledge, I could at least write up the first program.

Also, here is a very big Bash Script guide at http://tldp.org/LDP/abs/html/
It's got a lot of things and a very large number of examples which could help you.



None.

Jun 10 2010, 4:14 am rockz Post #4

ᴄʜᴇᴇsᴇ ɪᴛ!

Quote from BeeR_KeG
I've done a similar program to the first one using Intelx86 assembly during an exam last semester. It was pretty simple, we took each lower case letter and replaced it with an upper case letter and the upper case letters stayed the same. Using assembly will make it very easy, you'd just detect every character on the file and using the ASCII character values and a simple algorithm to detect and transform from binary to hexadecimal and you'd be set. For the second program, I believe the same idea can be used, but it could be a bit more complex since I haven't worked with picture files for assembly.

If you have DOS knowledge, I could at least write up the first program.

Also, here is a very big Bash Script guide at http://tldp.org/LDP/abs/html/
It's got a lot of things and a very large number of examples which could help you.
All my coding experience was writing a program which solves a problem which I already solved in excel. It was really a waste of my time.

Essentially all I want to do is edit/read a text file in both cases. The fact that the second file is a bmp is irrelevant (I'll probably end up cutting out the headers, leaving just the raw data behind).

I can get around in dos and linux, but I'm no expert.

I've seen that bash guide, but of course the idea of me reading any of that is mind boggling. In order for me to read that, I have to want to make this program enough to learn how to do 10x the stuff that I need to know. I find it much easier for me to learn when I WANT to do something (like I'd write the program if I knew how to read/write the file in the proper manner; that's the only thing I'm unsure of, and trying to find it in that guide is rather difficult without reading it completely).

Edit:
somehow the complexity of the first program seemed greater. I have solved that conundrum, since it was easy to do via find/replace (only needed 26 times). However, it's still a program I would like to learn how to do, since I think it ties in well with the color counter.

Post has been edited 1 time(s), last time on Jun 10 2010, 5:08 am by rockz.



"Parliamentary inquiry, Mr. Chairman - do we have to call the Gentleman a gentleman if he's not one?"

Jun 10 2010, 7:32 am NudeRaider Post #5

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

Not bitching or anything, but I wondered if there's a reason you ignored my post?
Or is it because you want/need to do it in bash?




Jun 10 2010, 11:54 am rockz Post #6

ᴄʜᴇᴇsᴇ ɪᴛ!

haven't had a chance to look at it.



"Parliamentary inquiry, Mr. Chairman - do we have to call the Gentleman a gentleman if he's not one?"

Jun 10 2010, 4:34 pm Biophysicist Post #7



See attachments.

Attachments:
RockzTextConvWut.exe
Hits: 4 Size: 74kb
source.txt
Hits: 5 Size: 1.55kb



None.

Jun 10 2010, 5:48 pm NudeRaider Post #8

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

Is that for Linux or something? Because I can't run it on my Win XP 64bit.




Jun 10 2010, 6:02 pm Biophysicist Post #9



It was written on Windows 7 using the current version of VC++ Express Edition (which is a Microsoft product), so it wouldn't have any "O NOES DO NOT RUN ON WINDOWZE" stuff (though it should run under anything... I didn't use any DLLs or OS-specific stuff, to my knowledge.)

What exactly goes wrong? Does nothing happen whatsoever? If so, try running it from a command prompt.



None.

Jun 10 2010, 6:10 pm NudeRaider Post #10

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

When started from desktop:
"This application cannot be started since the application configuration is not in proper form. To solve this problem reinstall the application."
(Tried to translate this strange message to the best of my ability.)

console message: "The system cannot execute the specified program."




Jun 10 2010, 6:12 pm Biophysicist Post #11



Ah. It could be because you're using 64bit, in which case I can't help you afaik... But I'll try anyway. ;P

EDIT: Odd... It seems that VC++ apps need a particular DLL in order to run. Dunno why. >.>



None.

Jun 10 2010, 7:40 pm ShadowFlare Post #12



In the options for your project, you can configure it to statically link in the C/C++ libraries instead of using a DLL. The default is to use a DLL. There are reasons that the DLL option can be useful and there are reasons the other option can be useful (like if you want a standalone program that doesn't need those DLL files).



None.

Jun 15 2010, 10:45 pm rockz Post #13

ᴄʜᴇᴇsᴇ ɪᴛ!

Quote from NudeRaider
http://www.actool.net/files/actoolinstall_540.exe
Is a pretty powerful macro generator. It's able to handle strings, write and read files and even read colors of screen pixels.
Its syntax is pretty easy to learn if you know any programming language and each command has a pretty good help.
I haven't done much with it so I'm not sure how useful it is for your specific case, but it should be worth checking out.
Alright, so I got to program, looked at it, and I figure I can pretty easily get it to work, but the problem is that it's got the "fileread" command which reads a line. Well I only want it to read 3 bytes.



"Parliamentary inquiry, Mr. Chairman - do we have to call the Gentleman a gentleman if he's not one?"

Jun 15 2010, 11:16 pm O)FaRTy1billion[MM] Post #14

👻 👾 👽 💪

Quote from BeeR_KeG
I've done a similar program to the first one using Intelx86 assembly during an exam last semester. It was pretty simple, we took each lower case letter and replaced it with an upper case letter and the upper case letters stayed the same. Using assembly will make it very easy, you'd just detect every character on the file and using the ASCII character values and a simple algorithm to detect and transform from binary to hexadecimal and you'd be set.
Just for each byte that is >= 0x41 and <= 0x5A do or 0x20. ;o Everything is now uppercase.

Processing images with ASM is also easy (I don't know x86, though :P). Bitmaps are especially easy because of their format ...



TinyMap2 - Latest in map compression! ( 7/09/14 - New build! )
EUD Action Enabler - Lightweight EUD/EPD support! (ChaosLauncher/MPQDraft support!)
EUDDB - topic - Help out by adding your EUDs! Or Submit reference files in the References tab!
MapSketch - New image->map generator!
EUDTrig - topic - Quickly and easily convert offsets to EUDs! (extended players supported)
SC2 Map Texture Mask Importer/Exporter - Edit texture placement in an image editor!
\:farty\: This page has been viewed [img]http://farty1billion.dyndns.org/Clicky.php?img.gif[/img] times!

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[07:47 pm]
Ultraviolet -- Yeah, I suppose there's something to that
[2024-5-06. : 5:02 am]
Oh_Man -- whereas just "press X to get 50 health back" is pretty mindless
[2024-5-06. : 5:02 am]
Oh_Man -- because it adds anotherr level of player decision-making where u dont wanna walk too far away from the medic or u lose healing value
[2024-5-06. : 5:01 am]
Oh_Man -- initially I thought it was weird why is he still using the basic pre-EUD medic healing system, but it's actually genius
[2024-5-06. : 3:04 am]
Ultraviolet -- Vrael
Vrael shouted: I almost had a heart attack just thinking about calculating all the offsets it would take to do that kind of stuff
With the modern EUD editors, I don't think they're calculating nearly as many offsets as you might imagine. Still some fancy ass work that I'm sure took a ton of effort
[2024-5-06. : 12:51 am]
Oh_Man -- definitely EUD
[2024-5-05. : 9:35 pm]
Vrael -- I almost had a heart attack just thinking about calculating all the offsets it would take to do that kind of stuff
[2024-5-05. : 9:35 pm]
Vrael -- that is insane
[2024-5-05. : 9:35 pm]
Vrael -- damn is that all EUD effects?
[2024-5-04. : 10:53 pm]
Oh_Man -- https://youtu.be/MHOZptE-_-c are yall seeing this map? it's insane
Please log in to shout.


Members Online: Roy