Posts

Showing posts from November, 2017

How do I add text to the beginning of a file in Bash?

echo 'task goes here' | cat - todo . txt > temp && mv temp todo . txt or sed - i '1s/^/task goes here\n/' todo . txt or sed - i '1itask goes here' todo . txt

CHECK!!! bash course

bash course exit 0 read -a export VAR not subshell profile subshells bashrc user top kill pid telnet 0 cat -vet 0 stdin, 1 stdout, 2 stderr pipeline stdout-)stdin grep -E '[A-Z][a-z]+\b' file.txt grep -l n c grep ^...$ #find any 3 chars sed  -r s c a y I p whereis fdisk -l udev daemon chntpw su - vs su su - logs you in completely as root, whereas su makes it so you are pretending to be root. mount -o remount,rw / parted -k gpt gui uefi partitions )2tb (part 2) partitions primary extended logical have compiled your own kernel at some point, know how to trace syscalls, understand TCP, care about the difference between sysvinit/runit/systemd, etc man 7 signal trap kill term int substitution operators ${VAR:-word} pattern matching ${BLA#bla*} optarg man test pncopy strace -c ls hup vs kill var/log/messages centos rpm qa in ubuntu yum update apt.get update redhat satelite ubuntu landscape tools for deployment root.system.people sudo su ls --help show options cd equal cd ,,~ rm -rf

sed http://www.pement.org/sed/sed1line.txt

http://www.pement.org/sed/sed1line.txt

sed -i 's/fea/asd/g' hello.txt | sed "/bam/ s/foo/bar/" # Replace foo with bar on lines contain 'bam' | sed -i '1s/^/head2\n/' file1

sed - i 's/fea/asd/g' hello . txt g:  Global s:  substitute -i  : realtime works with file --- sed "/bam/ s/foo/bar/" # Replace foo with bar only on lines that contain 'bam'. #add text at the begining sed -i '1s/^/head2\n/' file1

Filter out lines containing 'spam': sed '/spam/d' somefile | Capitalize all vowels in a file: sed 'y/aeiou/AEIOU/' somefile

Filter out lines containing 'spam':   sed  '/spam/d' somefile Capitalize all vowels in a file:  sed 'y/aeiou/AEIOU/' somefile

Print the first seven lines of a file using sed: sed 7q | delete from line 3 up to end: sed 3,/^$/d filename

Print the first seven lines of a file using  sed :  sed  7q <file> delete from line 3 up to and including first blank line: sed 3,/^$/d filename ubu1404@ubuntu1404lb01:~$ cat f 1 2 3 4 5 ubu1404@ubuntu1404lb01:~$ sed 3,/^$/d f 1 2 ubu1404@ubuntu1404lb01:~$ seq 6 >> f ubu1404@ubuntu1404lb01:~$ sed 3,/^$/d f 1 2

print lines 3 through 7 of a file: sed -n '3,7p' somefile | sed -i '4s/xxx/bbb/' f1

print lines 3 through 7 of a file:  sed  -n '3,7p' somefile Trim leading and trailing whitespace sed -i 's/^[ \t]*//;s/[ \t]*$//' somefile ============ sed - i 'Ns/.*/replacement-line/' file . txt where  N  should be replaced by your target line number. This replaces the line in the original file. To save the changed text in a different file, drop the  -i  option: sed 'Ns/.*/replacement-line/' file . txt > new_file . txt centos@192 Documents]$ sed -i '2s/aaa/bbb/' f1 [centos@192 Documents]$ cat f1 aaa bbb aaa bbb aaa