Open log file and read from the bottom - fopen

Quick question,
Is it possible to open a log file and read it from below?
I know you can do this;
fopen('/var/log/messages','r')
But this read the file from the top.
This takes quite some time when the file is too big in size.
Would it be possible to read the file from bottom to top?
Thank you
Wesley

You can implement the following Pseudocode for the solution of your problem:
fopen('/var/log/messages','r')
while (fgets () != NULL)
{
push line to stack
}
open output file
while (stack no empty)
{
pop stack
write popped line to file
}

Related

Point alway replace first time open file in vs-code

When I open the first file the point so weird:
It replaces my text I don't want this I want to insert in the position of my point
With these issues, I remove some extension, and It disappear

VS-Code Extension: vscode.window.activeTextEditor == undefined

I wrote an Visual Studio Code extension.
Based on this example:
https://github.com/Microsoft/vscode-extension-samples/tree/master/previewhtml-sample
var editor = vscode.window.activeTextEditor;
if (!editor) {
console.log("No open text editor");
}
This works fine if i open a 2MB File.
But not if the file is 5MB or larger.
But if I copy (Ctrl+C,Ctrl+V) a 10MB into a new editor it will work and is prety fast.
Has anyone an idea what kind of limitation this is?
Or is there perhaps a work around by some how let user choose a file in command.
To directly read the file?
This was addressed upstream in this issue
The root cause was that VS Code did not properly create text editors for files over a certain size. That size limit has since increased but you still may run into this limitation for very large files

Merging two files in Notepad

Hi i have two long files both 30k lines long. Is there any way of merging them like that in Notepad++ or using other software?
1st line from 1st file: 1st line from second file
If you happen to have python on your computer, using itertools you can merge both files. Keep in mind that if one file ends before the other, whichever file keeps going will continue to put their lines into the output file.
from itertoools import izip
with open("outputfile.txt", 'w') as output:
with open ("firstfile.txt") as f1 , with open ("secondfile.txt") as f2:
for file1,file2 in zip(f1,f2):
output.write(f1)
output.write(f2)
For decades there have existed a command to do exactly this, paste. Example:
$ cat > file1
one
two
three
$ cat > file2
1
2
3
$ paste file1 file2
one 1
two 2
three 3
$
The free gnu version is currently part of coreutils, which I think is simplest to install via cygwin. If you need the separator to be exactly colon+space you can just pipe paste's output through sed 's/\t/: /'.
Here is a possible solution using Excel:
1.)
Open the first file with Excel (all the text should be in one column)
2.)
Open the second file with Excel (all the text should be in one column)
3.)
Go back to your first file and add a : to every row of the second column
4.)
Copy the first column of the second file and paste it to the third row of the first file
5.)
Save the combined file as *.txt file
this is not possible in Notepad as far as i know, so your best bet is Notepad++. is there a reason why you don't wanna use Notepad++?
EDIT: I see, i deserve that -rep :P sorry for not reading correctly.
What you do in Notepad++ is:
1. open Notepad++ and navigate to Plugins > Plugin Manager > Show Plugin Manager
2. look for and Check "Compare"
3. click "Install"
now what you do is you open your first file in Notepad++. after that, you open your second files inside the same window of Notepad++ and drag the second file to the middle of Notepad++ (so click and drag the second document to the middle of Notepad++) once you release, it will ask you what to do. Click on "Move next to eachother"
after you have done that, you can now click Plugin > Compare > Compare. this will comapre the 2 files and give you exactly whats different between them.
Sorry for putting the answer quickly without reading more carefully.

How to color text in private message in mIRC

am tring to input my each text line in private message colored, i use this code it is showing colored text but adding a space before text. how can i remove that space
on *:INPUT:?:{
say 4 $strip($1-)
halt
}
and also now commands like
/clear
is not working .. showing in read but its not working
on input events are sensible
if you dont know how it works, dont mess with it, since it may mess with all your scripts
try this
on *:input:?:{
if (!$inpaste) && (!$ctrlenter) && ($left($1,1) != /) {
command here
haltdef
}
}
by the way, this event must be on top of all on input events to work

MATLAB: uiopen AND get the name of that file?

I have a GUI that has pushbuttons. You push the button, it allows you to choose a file to open then loads that file into the workspace using uiopen('load'). This part works fine:
Then I would like it to return the name of the file it just opened, so that I can use it for telling the next part of the program which data to look at, and to get the name of the opened file to display in an edit box in the GUI itself. First issue more vital than second. Any help would be appreciated
thanks
Actually the function 'uigetfile' is usually used for openning standard dialog box for retrieving files, and the format is like:
filename = uigetfile
or
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec)
This function, displays a modal dialogbox that lists files in the current folder and enables you to selector enter the name of a file. If the file name is valid and the fileexists, uigetfile returns the file name as astring when you click Open. Otherwise uigetfile displaysan appropriate error message, after which control returns to the dialogbox. You can then enter another file name or click Cancel.If you click Cancel or close thedialog window, uigetfile returns 0.
one example could be:
[FileName,PathName] = uigetfile('*.m','Select the MATLAB code file');
Also, you can use 'uigetdir' for doing the same for directories.
In addition, you can check this link: for matlab
You can use uigetfile to get the name of the file and open it using load(filename).