Reading a txt file in terminal over a network
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.
Hope this helps you off in the right direction. |
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.
Anyone else know how to do this? |
Yes:
(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) Or: (4): Write your own protocol, use sockets, and have your own daemon running on the server. |
Try
/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 |
hi, today i managed to finish the code i was doing, just wanted to say thanx! ended up using the write and get command.
write(our_socket, "GET /~pjb/tmp/cnet221file.txt\n", 30); recv(our_socket, buffer, 1000, 0); printf("%s", buffer); |
All times are GMT -5. The time now is 02:13 PM. |