LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sed/awk for matching & substituition (https://www.linuxquestions.org/questions/programming-9/sed-awk-for-matching-and-substituition-233641/)

laikos 09-21-2004 11:42 PM

sed/awk for matching & substituition
 
Hi,
I would like to write a sed or awk script to do conversion for
/proc/partitions information to format that is understoodable by most people

Code:

# cat /proc/partitions
major minor  #blocks  name    rio rmerge rsect ruse wio wmerge wsect wuse running use aveq
  8    48  17921835 scsi/host1/bus0/target2/lun0/disc 294 187 3818 1450 3 0 24 0 0 1440 1450
  8    49  17920476 scsi/host1/bus0/target2/lun0/part1 293 184 3810 1450 3 0 24 0 0 1440 1450
  8    64  17921835 scsi/host1/bus0/target3/lun0/disc 8537 3 68284 40720 1 0 8 0 0 17940 40720
  8    65  17920476 scsi/host1/bus0/target3/lun0/part1 8536 0 68276 40710 1 0 8 0 0 17930 40710
  8    80  17958274 scsi/host1/bus0/target4/lun0/disc 2077 31422 267956 68450 1 0 8 0 0 38700 68450
  8    81  17952606 scsi/host1/bus0/target4/lun0/part1 2076 31419 267948 68450 1 0 8 0 0 38700 68450

from this information I want to convert it to format such as
Code:

/dev/sda
/dev/sda1
/dev/sda2

In doing that I believe the code should be able to do conversion
[0..25] -> [a..z]

Thanks for your help

zefo 11-22-2006 11:00 AM

probably a bit outdated reply but cat /proc/partitions on my system (archlinux 7.2) is:

3 0 39483743 hda
3 1 394834 hda1
3 2 938493 hda2
.
.

so i think no filtering is needed.

Tinkster 11-22-2006 12:19 PM

Not only is this outdated, it doesn't match his system; he's is (was?)
using devfs on a Slackware machine.


Cheers,
Tink

jschiwal 11-22-2006 12:44 PM

Since sudo fdisk -l does the conversion already, perhaps:
sudo /sbin/fdisk -l | awk '/^\/dev/ {print $1}'

You could edit the sudoers file (with visudo normally) to use this oneliner.


All times are GMT -5. The time now is 04:37 AM.