vi, sed, and awk

revnja

Platinum Member
Feb 1, 2004
2,864
0
76
Yes, and I love each and every one of them like my own children. Grep is neat-o too.
 

jinduy

Diamond Member
Jan 24, 2002
4,781
1
81
vi - unix text editor
sed --- never used it... i just know it's really useful for replace characters within a file
awk --- i heard it does line by line processing of text files...

can anyone list practical uses for awk?
 

Reel

Diamond Member
Jul 14, 2001
4,484
0
76
Originally posted by: jinduy
can anyone list practical uses for awk?

Suppose you have a log file that has a number of fields and you only want the 4th field delimited by some symbol. You could use awk to quickly do that then pipe it into another file.
 

vi edit

Elite Member
Super Moderator
Oct 28, 1999
62,484
8,345
126
Aren't those guns you can use in Counterstrike?
 

ScottMac

Moderator<br>Networking<br>Elite member
Mar 19, 2001
5,471
2
0
These are all legacy *nix tools.

vi is a text editor, more common in Linux is vim (Vi IMproved). emacs is another editor; there are "religious" camps supporting either. Both can be very powerful; offering things like the application of regular expressions for text location, changes, filtering, etc.

Both also offer auto indent for programming, matching paren|brace|bracket and other programming-related features. emacs is LISP-based and permits the user (if they want to ) to write other operative modules for use in editing.

sed is "stream editor" - it can be used as a filter to extract, filter, change, or format (usually text) data as it's received at one place and moved to another .... like a log file or a serial stream.

awk is more of a text processing script language. You feed it a file name (for example) and, using tools like regular expressions, it'll make changes to the text in the file (or dump the changed text to another file ... it's usually bad juju to kill the original information until the proper changes have been confirmed (saves you from an interrupted process and / or other corruption).

grep is mostly used as a fliter (like "more|grep blah" or "ps -A|grep ftp) to located text within a stream or file ... it usually can describe the location (in a file, a line number, for example). grep's power comes from it's use of regular expressions.

Regular expressions are symbols used to describe the object of interest ... things like "^" to indicate a match starting at the begiinning of the line, "$" indicating the end of the line, "." matches any character ... then there are quantifiers like "+" to match zero or more positions, "*" match one or more positions, and "?" - match zero or one position.

So if you were scanning an email file, you might look for something like ^Sender:.*$ to find a line starting with("^") "Sender:, that contains one or more characters following (".*"), immediately followed by the end-of-line ("$")

(the above example is not necessarily good form, it's just an example)

If you have to evaluate large masses of text, wither on-the-fly or in a file (like log files) these tools, and regex can save a great deal of time and hassle.

O'Reilly has a great book on regular expressions called 'Mastering Regular Expressions' that does a great job of covering regex use.

FWIW

Scott
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
I personally find that perl renders sed, awk, etc. obsolete. You can do everything sed, awk or similar tools do in perl with a more robust regex "engine."

For example, if I want to process an input file line by line and replace something I might do...

cat somefile | perl -ne "s/somepattern//;" > somefile.out

Much easier and more flexible, imo.
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
Originally posted by: LoKe
On a somewhat related note; vi sucks. =D

It doesn't suck, it's very powerful - but it's also difficult to use because there's a lot of commands to remember. I prefer to use a full-featured Windows text editor though.
 
Jun 4, 2005
19,723
1
0
Originally posted by: mugs
Originally posted by: LoKe
On a somewhat related note; vi sucks. =D

It doesn't suck, it's very powerful - but it's also difficult to use because there's a lot of commands to remember. I prefer to use a full-featured Windows text editor though.

When it comes to editing, I need my GUI's.