sed 'Nq;d' file.txt
echo "new content" | cat - file.txt > temp
mv temp file.txt
sed -i '1s/^/new content\n/' file.txt
sed -i '/^\s*$/d' file.txt
# N should be the target line number
sed -i 'Nd' file.txt
# N should be the target line number
sed -i 'Ns/.*/replacement-line/' file.txt
cat << EOF > file.txt
The current working directory is $PWD.
You are logged in as $(whoami).
EOF
Suppose we have two files: packages.fedora and packages.
packages.fedora:
autossh
bash-completion
bat
bc
borgmatic
bzip2
cmake
curl
diff-so-fancy
diffutils
dnf-plugins-core
packages:
bash-completion
bc
bzip2
curl
diffutils
dnf-plugins-core
To plain-print the lines that exist in packages.fedora but do not exist in packages:
comm -23 <(sort packages.fedora) <(sort packages)
Output:
autossh
bat
borgmatic
cmake
diff-so-fancy
comm command compares two sorted files line by line.-23 flag is shorthand for -2 and -3.-2 suppresses column 2 (lines unique to packages).-3 suppresses column 3 (lines that appear in both files).
split -l 60 bigfile.txt prefix-
while read line; do
echo "$line";
done </path/to/file.txt
cat urls.html | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*"
To find all cron processes with ps aux:
ps aux | awk 'NR<2{print $0;next}{print $0 | grep "cron"}' | grep -v "awk"