function copy() {
if [[ $# -eq 0 ]]; then
echo 'first argument: file'
echo 'second argument: line number'
else
sed -n $2p $1 | pbcopy
fi
}
if the file is hello.txt
cat hello.txt
cat -n hello.txt (returns the file with the line numbers)
and if you want to copy one line
copy hello.txt 2 (for line 2)
or if you want to copy from an entire text file:
function copyfile() {
if [[ $# -eq 0 ]]; then
echo 'first argument: file'
echo 'second argument: line number'
else
cat $1 | pbcopy
fi
}
copyfile hello.txt
will return the entire file in your clipboard