Introduction to string processing

Introduction to string Processing

Head/Tail

Head and tail command are used to view the first and last few lines of a file respectively.

By default these commands generate 10 numbers of lines.

# head /etc/passwd (shows first 10 lines)

# tail /etc/passwd (shows last 10 lines)

One very handful command to monitor log messages

#tail -f /var/log/messages  (this is used to see the online activities)

wc: Word count

This command is used to count number of lines, words or characters in file

Syntax:

wc <option> filename

Options: -l counts number of lines

-w counts number of words

-c counts number of characters

# wc -wlc *

Cut: cut command cut the specified field from the file of known formats or to cut first few characters

#cut <option> <filename>

Options:  d -delimiter or field separator

-f{number} -field number

-c -to cut the characters

#cut -d: -f1 /etc/passwd (shows only the first field of /etc/passwd’s contents

#cut -d: -f1-3 /etc/passwd (shows only first second and third fields of /etc/pas                                    swd contents)

#cut -c1-10 /etc/passwd (shows first 10 characters of file’s line)