How can I read a single line from a text file using bash?

  • Thread starter Thread starter Euclid
  • Start date Start date
  • Tags Tags
    Automated files
AI Thread Summary
The discussion centers around creating a bash script for automatically backing up documents to a remote computer, specifically focusing on backing up only newer versions of files. The script involves connecting to a remote computer via SSH, generating a list of files in the local Documents directory, and checking if each file has a newer version than the one stored on the remote machine. The user seeks assistance with reading a text file line by line in bash to facilitate this process. A suggestion is made to consider using rsync, which efficiently handles file synchronization by transferring only the changed parts of files, simplifying the backup process significantly.
Euclid
Messages
213
Reaction score
0
I want to write a script that will automatically backup my documents to a remote computer. I have a lot (~500 MB) of files, so I only want the files to be backed up when a newer version exists.

Short version of the question: how do I read a single line from a text file using bash?

Long version of the question:
Here is the plan for the script...

#!/bin/bash
ssh remoteComputer # connect to remote comp
find ~/Documents * > files.txt #find all files in documents and write to files.txt
line=1
fileLength = (number of lines if files.txt)
while [line -lte fileLength]
do
(put filename at the lineth line to the string fileName)
if fileName -nt remoteComputer:~/Documents/fileName
#go through all files and
#check to see if remoteComputer has the
#latest version of this file already
scp line to remoteComputer
#if so, update file
fi
line=$[$line+1]
done
exit #leave ssh session

The exact implementation is what I need help on. If I could read files.txt line by line this would be very easy, but I can't figure it out!
 
Technology news on Phys.org
You should look at rsync, it not only does this but can copy just the parts of files that have changed.
 
That's just too easy! Thanks mgb_phys!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top