A simple script to copy content from a file, specifying a starting and an ending line.
-
Root privileges.
-
sedandxclip(andgitif you want to clone the repo).The
sedpackage is commonly pre-installed in the Linux distros.But
xclipis not a package included by default.
In Debian-based:
sudo apt install sed xclip
With pacman (arch-based):
sudo pacman -S sed xclip
For Fedora:
sudo dnf install sed xclip
Now, if you have sed and xclip you can install the script.
Clone the repo and set up the script:
git clone https://github.com/FabrizioJordan/copyFromFile.git && cd copyFromFile
chmod +x copyFromFile && sudo cp copyFromFile /usr/local/bin
But if you want a shorter command, you can create a alias like cpff or cpFromFile.
Or you can run this command (to create a Symlink):
sudo ln -s /usr/local/bin/copyFromFile /usr/local/bin/cpff
Update is so easy
Now you have two options
Using an argument with the command -> Like this:
copyFromFile --update
From the terminal -> Only run this command:
git clone https://github.com/FabrizioJordan/copyFromFile.git && cd copyFromFile && sudo cp copyFromFile /usr/local/bin/copyFromFile && cd .. && rm -f copyFromFile
Its easy. You only need to pass three arguments.
-
The starting line.
-
The ending line.
-
The file name.
But you have two arguments:
-
-a | --allWith this argument only pass the file.
-
-o | --one-lineThis argument needs the line to copy and the file.
This examples shows how this script can be used easilly:
This example copies the content from the line 10 to line 30 in file.txt file.
copyFromFile 10 30 file.txt
If you created an alias, you can use it in the same way:
cpff 10 30 file.txt
The next example copies all of the content from the file.txt file.
copyFromFile --all file.txt
Finally, the --one-line argument, this argument copies only one line from the file and is easy to use.
copyFromFile --one-line [Line] [File]
Example:
copyFromFile --one-line 5 file.txt
-h | --help: Shows the help menu
-u | --update: Updates the program
-v | --version: Shows the actual version of the program
-a | --all: Copies all of the content from the file
-o | --one-line: Copies only one line from the file
During installation, the script is copied to /usr/local/bin. If you wish to uninstall it, follow these steps:
To remove the script:
find /home/ -type f -name "copyFromFile" -exec rm {} \; && sudo find /usr/ -type f -name "copyFromFile" -exec rm {} \;
If you renamed the script during installation (e.g., to cpff):
find /home/ -type f -name "cpff" -exec rm {} \; && sudo find /usr/ -type f -name "cpff" -exec rm {} \;