Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jan 272010
 

Extract column data using awk

Answer:

A simple awk command print the 1st column of top command

# top -bc -n1 | awk '{print $1}'

If you want to specify the field separator, you can do the following

# awk -F':' '{print $1}' /etc/passwd

Which print the 1st column of file /etc/password, as if they are split by :

Jan 262010
 

Print a particular column data using awk

Answer:

Consider you have a file text.txt like below

1 one
2 two
3 three

How would you only print the second column?

It can be easily done using awk

# awk '{print $2}' text.txt
one
two
three

Try the above command with $1, $2, $3 etc.

Jan 242010
 

Serve current directory using HTTP with a single command

Answer:

Sometimes, you want to share some files in a given directory in your Linux system to other people, you might consider setup a NFS, Samba, FTP or so.

However, the easiest method is to export the directory using HTTP, with the help of Python.

E.g.

 # cd /data/
python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...

Now people can access the web server at port 8000 of your system's IP address, to access the /data directory.