ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hi, very new to linux and am trying to create a program that connects to a remote text file from another computer and displays the txt file on the screen.
I'm trying to make it so it misses out all the header stuff when its displayed and i know there are 2 new lines before the text starts so i was told that i could do a search for the 2 new lines then display all txt after that?
Anyone got any ideas on what to do or where to start?
One idea - log into the remote system using ssh. Once there you can use "less" to view the file. less has a _bunch_ of command line options, including searching for patterns and displaying all text after them, and moving down a specific number of lines and displaying everything after that. Read the man page ("man less") for a full explanation. In any case, if you are leaving this ssh session open you can just use the "R" command to refresh your view of the file using your original command.
apparently less is used to view text files.. totally different from programming something to download a text file, you have to open a socket, send the HTTP command to get the file, and display it.
(1): Use a network file system.
(2): Do what you said, open a socket and request it via HTTP
(3): Use wget, store it in a temporary file, and display it, like so:
Code:
int main(int argc, char **argv)
{
FILE *Handle;
system("wget http://www.myserver.com/textfile.txt");
Handle = fopen("textfile.txt", "rb");
/* Skip first two lines */
while(!feof(Handle)) printf("%c", fget(Handle));
fclose(Handle);
}
That would work.
Or:
(4): Write your own protocol, use sockets, and have your own daemon running on the server.
/tmp/local.txt will have copy of remote /path/to/file. If you are using it in script make sure you use ssh-keys to avoid password prompt just see howto do this http://www.cyberciti.biz/nixcraft/vi...ntication.html
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.