Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: New Line In File  (Read 6949 times)

0 Members and 1 Guest are viewing this topic.

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
New Line In File
« on: January 17, 2009, 07:16:06 PM »
OK, I need your help again :-\


In priorities:
1. I'm trying to get the contents, and set each line as a variable.
2. If the linecount exceeds a certain amount (30 for example) delete the first line and move everything up a line.


The FOR command might work here, but I don't know how to set the delimiter as a new line...and the eol thing doesn't do anything either.
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Dias de verano

  • Guest
Re: New Line In File
« Reply #1 on: January 18, 2009, 02:16:13 AM »
1. I'm trying to get the contents, and set each line as a variable.

Could you explain this a bit more ... do you mean you want to get each line into a variable, do something with that variable, then move on to the next line and repeat until all lines are done?

Quote
2. If the linecount exceeds a certain amount (30 for example) delete the first line and move everything up a line.

Understood that 30 is an example. Do you mean that if the file has 36 lines, trim it down to 30 lines, discarding the top 6 lines? Or will it be monitored so if it ever gets over 30 it is trimmed at once? So that 31 is the biggest it ever gets?

And you are enquiring about making the FOR delimiters the beginning and end of a line? That is, take the whole line? Can do that now. It's "delims="
« Last Edit: January 18, 2009, 02:36:56 AM by Dias de verano »

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: New Line In File
« Reply #2 on: January 18, 2009, 09:05:18 AM »
1. I'm trying to get the contents, and set each line as a variable.

Could you explain this a bit more ... do you mean you want to get each line into a variable, do something with that variable, then move on to the next line and repeat until all lines are done?

Quote
2. If the linecount exceeds a certain amount (30 for example) delete the first line and move everything up a line.

Understood that 30 is an example. Do you mean that if the file has 36 lines, trim it down to 30 lines, discarding the top 6 lines? Or will it be monitored so if it ever gets over 30 it is trimmed at once? So that 31 is the biggest it ever gets?

And you are enquiring about making the FOR delimiters the beginning and end of a line? That is, take the whole line? Can do that now. It's "delims="

1. I'm trying to get the contents, and set each line as a variable.

Could you explain this a bit more ... do you mean you want to get each line into a variable, do something with that variable, then move on to the next line and repeat until all lines are done?

Quote
2. If the linecount exceeds a certain amount (30 for example) delete the first line and move everything up a line.

Understood that 30 is an example. Do you mean that if the file has 36 lines, trim it down to 30 lines, discarding the top 6 lines? Or will it be monitored so if it ever gets over 30 it is trimmed at once? So that 31 is the biggest it ever gets?

And you are enquiring about making the FOR delimiters the beginning and end of a line? That is, take the whole line? Can do that now. It's "delims="


1. That's correct. My program refreshes every 2 seconds, but when the linecount is over 30, it get's really jumpy. I just want to remove this problem without having to delete the whole file, then start again.

2. I was thinking about that solution, but wasn't sure if it would work or not. And just a question, what would happen if there are more than 26 of them??? Like, I start at %a , but what happens after I get to %z and there's still more lines to go?
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Dias de verano

  • Guest
Re: New Line In File
« Reply #3 on: January 18, 2009, 12:12:20 PM »

1. That's correct. My program refreshes every 2 seconds, but when the linecount is over 30, it get's really jumpy. I just want to remove this problem without having to delete the whole file, then start again.

You would have to count the lines in the file, and if there were more than 30, copy the last 30 lines of the file into another file, delete the original file, then rename the second file to the original filename. This might not be possible if the first file was in use by another program.

Quote
And just a question, what would happen if there are more than 26 of them??? Like, I start at %a , but what happens after I get to %z and there's still more lines to go?

I don't get this at all. Why do you want ALL of the lines in the file existing as variables all at once? Why would you need to do that?

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: New Line In File
« Reply #4 on: January 18, 2009, 04:33:57 PM »
Quote
I don't get this at all. Why do you want ALL of the lines in the file existing as variables all at once? Why would you need to do that?

I might be wrong, but I suspect it's related to this post.

You can get the data into a "pseudo" array by using a stem.tail construct used in some of the other languages (most notably REXX). You cannot however address the array as a single unit.

Code: [Select]
@echo off
setlocal
set fname=drive:\path\file.ext

for /f "tokens=* delims=" %%x in (%fname%) do (
call set /a dx=%%dx%%+1
)

set /a last=%dx%-30
if %last% LSS 0 (
for /f "tokens=* delims=" %%x in (%fname%) do (
call set /a idx=%%idx%%+1
call set array.%%idx%%=%%x
)
) else (
for /f "skip=%last% tokens=* delims=" %%x in (%fname%) do (
call set /a idx=%%idx%%+1
call set array.%%idx%%=%%x
))

for /l %%x in (1,1,%idx%) do call echo %%array.%%x%%

Be sure to change the value of fname. Keep in mind that batch coding like this is more of a parlor trick than anything particularly useful. Better to find a language that is not so underpowered.

 8)

Note: if your file contains any NT batch special characters, the results are unpredictable.
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: New Line In File
« Reply #5 on: January 18, 2009, 06:29:13 PM »
Quote
I don't get this at all. Why do you want ALL of the lines in the file existing as variables all at once? Why would you need to do that?

I might be wrong, but I suspect it's related to this post.

You are correct, it is related, but for a secret that has to remain vetween my friend and I, I can't reveal the complete reason why I actually need each line as a variable (one reason that I'm allowed to talk about is what I said before, my other script gets jumpy).

I will try the script.

EDIT: Tried the script...Just echos %fname% then closes...Can you explain how the code works so I can try and fix the problem myself?
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: New Line In File
« Reply #6 on: January 18, 2009, 06:57:14 PM »
Did you set fname variable to the label of a file on your system?

Quote
Tried the script...Just echos %fname% then closes

There is no echo %fname% instruction in the script. I'm as surprised as you!

Quote
but for a secret that has to remain vetween my friend and I, I can't reveal the complete reason why I actually need each line as a variable (one reason that I'm allowed to talk about is what I said before, my other script gets jumpy).

<sigh> Still compressing/decompressing files?

The first block of the script count the records in  the file

The second block subtracts 30 from the recordcount and either loads the array from the file (recordcount - 30 is negative) or skips recordcount - 30 records before loading the array

The third block lists out the contents of the array

I can't duplicate your error. There may have been an error when you copied/pasted the code into your editor.

 8)

Batch code does cloak and dagger. Who knew?
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: New Line In File
« Reply #7 on: January 18, 2009, 07:09:24 PM »
it's a super secret algorithm... the secret has been lost for ages... since the release of windows 3.1 it has lain forgotten.

It's basically a variation of Run length encoding. Ideally it would work, but unfortunately without looking at the "big picture" - otherwise proved by the proposal to replace words with letters, which won't work since those letters may appear in other words - so basically, it's not exactly a "super secret" technology that one must strive to protect.
I was trying to dereference Null Pointers before it was cool.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: New Line In File
« Reply #8 on: January 18, 2009, 07:35:03 PM »
Pardon me for butting in.
Is this just and exwercise, or is there a real need for this.
Does another program have the file open? If so, it would be hard to delete
anything from it. Why not just compile a small program the reads all the lines in a file and spits out the last thirty? Orr is there a reason to have 30 variables set to the 30 lines?

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: New Line In File
« Reply #9 on: January 18, 2009, 07:35:52 PM »
I made a mega compression algorithm that can compress anything into a single bit.

Unfortunately it cannot be decompressed.
I was trying to dereference Null Pointers before it was cool.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: New Line In File
« Reply #10 on: January 18, 2009, 08:38:15 PM »
Quote
if you understand this: (0x2b||!0x2b)
you are a programmer.
I am a programmer and I have no idea of what you mean.
I learned to program in COBOL

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: New Line In File
« Reply #11 on: January 18, 2009, 09:20:31 PM »
Quote
if you understand this: (0x2b||!0x2b)
you are a programmer.
I learned to program in COBOL


like I said.

besides, It doesn't say of you don't understand it your not a programmer... but anybody who does likely is.

it's shakespeare.
I was trying to dereference Null Pointers before it was cool.

Dusty



    Egghead

  • I could if she would, but she won't so I don't.
  • Thanked: 75
  • Experience: Beginner
  • OS: Windows XP
Re: New Line In File
« Reply #12 on: January 19, 2009, 12:25:14 AM »
Quote
it's shakespeare.

Hamlet? 0x2B | ~ 0x2B
One good deed is worth more than a year of good intentions.

Dias de verano

  • Guest
Re: New Line In File
« Reply #13 on: January 19, 2009, 12:38:21 AM »
for a secret that has to remain vetween my friend and I, I can't reveal the complete reason why I actually need each line as a variable (one reason that I'm allowed to talk about is what I said before, my other script gets jumpy).

When you are much older, say about 14, maybe you'll stop dicking around?  ::)

THis is where I say "goodbye".

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: New Line In File
« Reply #14 on: January 19, 2009, 01:04:01 AM »
Quote
it's shakespeare.

Hamlet? 0x2B | ~ 0x2B

well... yeah but mines the C version!

the VB version would be- &H2B Or Not &H2B which is FAR to obvious.
I was trying to dereference Null Pointers before it was cool.