About Me

My photo
Working as Technical Lead in CollabNET software private limited.

Thursday 28 August, 2008

AWK Samples


Here are some of the useful awk program collections!
awk '{print $2,$1}' filename
awk '{print $2,$1}' filename
awk '$1 > $2 {print $1,$2,$1-$2}' filename
awk '$1 > $2'           filename
awk '$1 > $2{print}' filename
awk '$1 > $2{print $0}' filename

awk '$1=="foo"{print $2}' filename
awk '/foo.*bar/{print $1,$3}' filename
awk '$2~/foo/{print $3,$1}' filename
awk '$2!~/foo/{print $3,$1}' filename

awk '/foo/,/bar/' filename
awk 'BEGIN{print"fee"} $1=="foo"{print"fi"}
END{print"fo fum"}' filename

awk '{print $1,$NF }' filename
awk '{print NR,$0 }' filename
awk -F: '{print $1,$3 }' /etc/passwd
awk '{$10=""; print }' filename
awk '{for(i=1;i<=NF;i++) print $i }' filename awk '{printf("%s %03d %02d %.15g\n",$1,$2,$3,$3/$2); }' filename
awk '{for(i=NF;i > 0;i--) printf("%s",$i); printf("\n"); }' filename

Replace particular field of line using awk

I was trying to replace the particular field of a line and found a suggestion for that.


echo 'count ****** 50' | gawk '{$2="\"5AB0\"";print}'


The above gawk command replaces the ****** with 5ABo.

Wednesday 20 August, 2008

To delete windows partition from ubuntu.

1) Command to see the partition
sudo fdisk -l
2) Mount the windows partition
sudo mount /dev/sda1 /mnt/
3) Look for the files and verify the data
ls -rlt
4)Then look for the available file system
sudo mkfs.
5)Create the new file system
sudo mkfs.ext3 /dev/sda1
6)Finally mounting the created partition
sudo mount /dev/sda1 /mnt/

To change the file system.
sudo vim /etc/fstab

To remove windows during bootup
cd /boot/grub/
sudo vim menu.lst
sudo grub-install /dev/sda


For referrence:
prakash@prakash-laptop:/boot/grub$ cat /etc/fstab
# /etc/fstab: static file system information.
#
#
proc /proc proc defaults 0 0
# /dev/sda3
UUID=38683652-4d42-4885-a18a-aa1fede0ca9d / ext3 defaults,errors=remount-ro 0 1
# /dev/sda1
UUID=C2C8BE9CC8BE8DE3 /media/sda1 ntfs defaults,nls=utf8,umask=007,gid=46 0 1
# /dev/sda5
#UUID=F0F6AC07F6ABCC62 /media/sda5 ntfs defaults,nls=utf8,umask=007,gid=46 0 1
# /dev/sda4
UUID=cc9c91ad-8b78-417f-9e49-beee5eeb1486 none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
# /dev/sda5
/dev/sda5 /home ext3 defaults,errors=remount-ro 0 1
# /dev/sda1
/dev/sda1 /data ext3 defaults,errors=remount-ro 0 1

Wednesday 6 August, 2008

How to combine avi files together

Hi,
I was trying to combine the 2 avi files and finally came with the good output. Here are the commands I've used to do it.

1) First rename the files to be appended with sequential numbers in it.

cat v1.avi v2.avi > vtest.avi

2) Then invoke mencoder to get the audio and video synchronization.

mencoder -forceidx -oac copy -ovc copy vtest.avi -o vtest_final.avi