Actually, I need to remind myself to visit the Linux From Scratch project's pages more often, as it has so much useful info there. Basically it, and its sister projects, build versions of Linux totally from start (hence the name) and document the process in its entirety.
http://www.linuxfromscratch.org
Of course those Linux forms don't have the cool features of Puppy -- their Linux From Scratch LiveCD project is much more bloated (fills the CD) with less content and less features. However it does have the wonderful advantage of being almost completely documented. There is so much yummy information there...
BaCon - Bash-based Basic-to-C converter/compiler
Linux From Scratch
[color=blue]A life! Cool! Where can I download one of those from?[/color]
Help needed
Hey guys!
I'm having problems. I'm trying to take a file with some text strings and reading it in as an array. I need to be able to compare the array elements and create anew array of totally unique elements. the list i am using to learn how is as follows:
array[1] = "SP"
array[2] = "HP"
array[3] = "SP"
array[4] = "B-tip"
array[5] = "B-tip"
I need to create an array containing only the following:
array[1] = "SP"
array[2] = "HP"
array[3] = "B-tip"
I've been through the documentation and have some limited (last time I did things like this was over 30 years ago - before qbasic even ) programming experience. I think it used to be done in a double-loop (ie. For x = 1 to 5, for y = 1 to 5, etc) Of course that could just be for bubble loops...can't remember ...grrrr
I just can't seem to find a handle on it, so I turn to those more knowledgeable for assistance. Any help is appreciated!
Thanks!
E
.
I'm having problems. I'm trying to take a file with some text strings and reading it in as an array. I need to be able to compare the array elements and create anew array of totally unique elements. the list i am using to learn how is as follows:
array[1] = "SP"
array[2] = "HP"
array[3] = "SP"
array[4] = "B-tip"
array[5] = "B-tip"
I need to create an array containing only the following:
array[1] = "SP"
array[2] = "HP"
array[3] = "B-tip"
I've been through the documentation and have some limited (last time I did things like this was over 30 years ago - before qbasic even ) programming experience. I think it used to be done in a double-loop (ie. For x = 1 to 5, for y = 1 to 5, etc) Of course that could just be for bubble loops...can't remember ...grrrr
I just can't seem to find a handle on it, so I turn to those more knowledgeable for assistance. Any help is appreciated!
Thanks!
E
.
I just coded a solution for this.
It looks like you`re wanting to remove duplicate lines.
You don`t say what the delimiter is, I assume it`s NL$.
Read the file into a list and test it for dups. like this:
This code ignores any duplicate lines and makes an array.
I know Bash`s "uniq" will do the same, but I assume BaCon code is wanted.
Enjoy dude..!
.
It looks like you`re wanting to remove duplicate lines.
You don`t say what the delimiter is, I assume it`s NL$.
Read the file into a list and test it for dups. like this:
Code: Select all
OPEN File$ FOR READING AS file_
list$ = ""
WHILE NOT(ENDFILE(file_))
READ line$ FROM file_
IF ENDFILE(file_) THEN BREAK
IF INSTR(list$, line$) > 0 THEN CONTINUE
list$ = list$ & line$ & NL$
WHEN
CLOSE FILE file_
SPLIT list$ BY NL$ TO array$ SIZE Sz
I know Bash`s "uniq" will do the same, but I assume BaCon code is wanted.
Enjoy dude..!
.
Last edited by sunburnt on Fri 17 May 2013, 21:01, edited 3 times in total.
If you have the text strings as lines in a file called list.txt, likeThen you can list the unique strings like this:Then you can read the no_duplicates.txt file in using BaCon to do whatever else you want with it.
I don't know enough about BaCon to be able to give a fully BaCon solution, but it seems that if using the shell makes your task simpler it's worth using it.
Code: Select all
dog
cat
tree
world
dog
tree
Code: Select all
sort list.txt | uniq >no_duplicates.txt
I don't know enough about BaCon to be able to give a fully BaCon solution, but it seems that if using the shell makes your task simpler it's worth using it.
[color=blue]A life! Cool! Where can I download one of those from?[/color]
Dear all,
If we take miriam's list as a basis:
we can do this little bit of processing:
The function CAT is there just there for convenience - to read the 'list.txt' file into a string variable. There are many ways of doing this, but this is one of them. Note that it doesn't take care of numerics well. You would have to check for a numeric type (probably using REGEX) and then prepend the requisite number of space pads before sorting - not hard.
With kind regards,
vovchik
If we take miriam's list as a basis:
Code: Select all
dog
cat
tree
world
dog
tree
Code: Select all
' ------------------
FUNCTION CAT(STRING FILENAME$)
' ------------------
LOCAL fileline$, txt$ TYPE STRING
IF FILEEXISTS(FILENAME$) THEN
OPEN FILENAME$ FOR READING AS catfile
WHILE NOT(ENDFILE(catfile)) DO
READLN fileline$ FROM catfile
txt$ = CONCAT$(txt$, fileline$, NL$)
WEND
CLOSE FILE catfile
END IF
RETURN CHOP$(txt$)
END FUNCTION
' ------------------
FUNCTION UNIQ$(STRING org$)
' ------------------
' assumes OPTION BASE 0
LOCAL i TYPE NUMBER
LOCAL new$ TYPE STRING
SPLIT org$ BY NL$ TO tmp$ SIZE elements
SORT tmp$
FOR i = 1 TO elements - 1
IF tmp$[i] = tmp$[i - 1] THEN
tmp$[i - 1] = " "
END IF
NEXT i
SORT tmp$
JOIN tmp$ BY NL$ TO new$ SIZE elements
RETURN CHOP$(new$)
END FUNCTION
myoldlist$ = CAT("list.txt")
PRINT "Old list: ", NL$, myoldlist$
mynewlist$ = UNIQ$(myoldlist$)
PRINT "New list: ", NL$, mynewlist$
OPEN "newlist.txt" FOR WRITING AS newfile
WRITELN mynewlist$ TO newfile
CLOSE FILE newfile
With kind regards,
vovchik