saurabhchokshi |
06-15-2009 12:23 PM |
Truncate the Lines from the File
Hi,
I want to truncate the file once I found the desired pattern.
For Example :-
Input :-
Quote:
crw------- 1 vcsa tty 7, 3 Jun 13 01:22 /dev/vcs3
crw------- 1 vcsa tty 7, 4 Jun 13 01:22 /dev/vcs4
crw------- 1 vcsa tty 7, 5 Jun 13 01:22 /dev/vcs5
crw------- 1 vcsa tty 7, 6 Jun 13 01:22 /dev/vcs6
crw------- 1 vcsa tty 7, 128 Jun 13 01:21 /dev/vcsa
crw------- 1 vcsa tty 7, 129 Jun 13 01:21 /dev/vcsa1
crw------- 1 vcsa tty 7, 130 Jun 13 01:22 /dev/vcsa2
crw------- 1 vcsa tty 7, 131 Jun 13 01:22 /dev/vcsa3
crw------- 1 vcsa tty 7, 132 Jun 13 01:22 /dev/vcsa4
crw------- 1 vcsa tty 7, 133 Jun 13 01:22 /dev/vcsa5
crw------- 1 vcsa tty 7, 134 Jun 13 01:22 /dev/vcsa6
lrwxrwxrwx 1 root root 4 Jun 13 01:21 /dev/X0R -> null
crw-rw-rw- 1 root root 1, 5 Jun 13 01:21 /dev/zero
/dev/:
total 0
crw------- 1 root root 189, 130 Jun 13 01:21 2-2
crw------- 1 root root 189, 385 Jun 13 01:21 4-1
crw------- 1 root root 189, 513 Jun 13 01:21 5-1
crw------- 1 root root 10, 175 Jun 13 01:21 agpgart
crw------- 1 root root 10, 59 Jun 13 01:21 autofs
drwxr-xr-x 3 root root 60 Jun 13 01:21 bus
crw------- 1 root root 5, 1 Jun 13 01:22 console
lrwxrwxrwx 1 root root 11 Jun 13 01:21 core -> /proc/kcore
crw------- 1 root root 10, 63 Jun 13 01:21 cpu_dma_latency
/dev/bus:
total 0
drwxr-xr-x 8 root root 160 Jun 13 01:21 usb
/dev/bus/usb:
total 0
drwxr-xr-x 2 root root 60 Jun 13 01:21 001
drwxr-xr-x 2 root root 80 Jun 13 01:21 002
drwxr-xr-x 2 root root 60 Jun 13 01:21 003
drwxr-xr-x 2 root root 80 Jun 13 01:21 004
drwxr-xr-x 2 root root 80 Jun 13 01:21 005
drwxr-xr-x 2 root root 60 Jun 13 01:21 006
|
The Output should be :-
Quote:
crw------- 1 vcsa tty 7, 3 Jun 13 01:22 /dev/vcs3
crw------- 1 vcsa tty 7, 4 Jun 13 01:22 /dev/vcs4
crw------- 1 vcsa tty 7, 5 Jun 13 01:22 /dev/vcs5
crw------- 1 vcsa tty 7, 6 Jun 13 01:22 /dev/vcs6
crw------- 1 vcsa tty 7, 128 Jun 13 01:21 /dev/vcsa
crw------- 1 vcsa tty 7, 129 Jun 13 01:21 /dev/vcsa1
crw------- 1 vcsa tty 7, 130 Jun 13 01:22 /dev/vcsa2
crw------- 1 vcsa tty 7, 131 Jun 13 01:22 /dev/vcsa3
crw------- 1 vcsa tty 7, 132 Jun 13 01:22 /dev/vcsa4
crw------- 1 vcsa tty 7, 133 Jun 13 01:22 /dev/vcsa5
crw------- 1 vcsa tty 7, 134 Jun 13 01:22 /dev/vcsa6
lrwxrwxrwx 1 root root 4 Jun 13 01:21 /dev/X0R -> null
crw-rw-rw- 1 root root 1, 5 Jun 13 01:21 /dev/zero
|
So, Once I found the pattern something like /: or /<some name>/: or /name/name/: or /name/name:. I should stop searching my file and truncate the file.
Could you please help me out to write a script to truncate the file?
Thanks,
Saurabh Chokshi
|