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

I want to talking about the “awk” command running as a grep or sed .This command is a  pattern scanning and processing, if you can use it as correct while working that contain complex  file, so it can be usefull.Also you can use regular expression while using awk ,  if you need of course.But i recommended to you got to use regex with awk.

Let’s start the review this command step by step to understand whic how to work this.

This command that prints first column in ugur.txt.

[root@rhel6 ~]# awk ‘{print $1}’ ugur.txt
linux
LINUX
ugur
hacker
redhat
rhel
rhellinux
bash
init
OS
architecture

This command that prints first and second columns in ugur.txt. Continue reading

Share on Facebook