SED also knowns as the Stream Editor’ when you want to search somethings in files particulary with regex, you can use sed like grep or awk.I gave some example about the this stream editor for, that want to using regex with sed.

sed -n 354p /var/log/messages
Jun 12 03:42:18 rhel6 kernel: pci 0000:00:15.7: BAR 13: can’t allocate I/O resource
[0x1000-0x1fff]

Prints the first line of the file

sed -n ‘$p’ /var/log/messages
Jun 13 21:37:20 rhel6 pulseaudio[2836]: alsa-sink.c: We were woken up with POLLUT set —
however a subsequent snd_pcm_avail() returned 0 or another value < mi_avail.
Prints the last line.

sed -n 4,390p /var/log/messages
Prints lines ’4′ with ’390′.

sed -n ’1!p’ ugur.txt
Prints all line but line ’1′.

sed -n ’1,3!p’ ugur.txt
Prints all line but lines ’1′ and ’3′.

Continue reading

Share on Facebook