In Linux, there are many tools to process text and other forms of data. One tool that comes to mind is the AWK. The AWK scripting processes a file line by line and can produce a summary of its finding as header or footer.
TLDP provides a guide on AWK at http://tldp.org/LDP/abs/html/awk.html
EXAMPLE 1
Here is a demonstration of the AWK to extract the directories mounted.
STEP 1. Create an AWK script file called "myscript1.awk". This should contain two lines.
BEGIN{ printf("Display the third field\n"); }
{ print $3 }
STEP 2. Run the following command to use the AWK script.
mount -t ext2,ext3 | awk -f myscript1.awk
EXAMPLE 2
Without using an AWK script file, extract data from the file /etc/passwd and display the results to screen.
STEP 1. Run the following command
awk -F: '{ print $1 ":" $3 ":" $7 }' /etc/passwd
AWK have been used for more complex reporting but the above should give an idea of how this is done.
Looking at alternative computer software solutions for a variety of reasons. This includes price, computer security, virus prevention and reliability. Here are my notes and great that if it helps you, otherwise please understand what you are doing and not follow blindly. All works expressed are my own and does not necessarily express the products or organisations mentioned here.
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2008
(85)
-
▼
June
(13)
- My list of Linux commands
- R60 and wireless
- Cases on why we need to be open sourced
- Viewing the network
- Problems with FTP
- Multiple X servers - Xephyr and Xnest
- Installing KDE on Ubuntu (Kubuntu)
- CentOS kernel
- OSS Seminar 08 - Miri
- Mobile phone tools
- OpenOffice.org Document Recovery screen
- Transfer phonebook from Motorola V360 to SE K810i
- What AWK can do for Linux.
-
▼
June
(13)
2 comments:
the alternative of awk can be cut, cut provides simple way to extract data by columns, but recently I tend to use python to do the, I find the list in python are more powerful.
AWK is a lighter and have been available in all Linux. It is also part of the LPI test.
Post a Comment