Tuesday, June 12, 2007

Select Fields or Columns Using the cut Command

Selecting fields and columns is a common task for system administrators. The cut command is an ideal utility for accomplishing this task. Here are examples of its use (selecting disk slices and checking for passwords).

#df -k grep c0 grep d0s cut -b16-17
s0
s3
s4
s5
s7

#cut -d: -f1-3 /etc/shadow

# cut -d : -f 1-2,7 /etc/passwd
root:x:/sbin/sh
daemon:x:
bin:x:
sys:x:
adm:x:
lp:x:
uucp:x:
nuucp:x:/usr/lib/uucp/uucico
listen:x:
nobody:x:
noaccess:x:
nobody4:x:
t1:x:/bin/csh
restrict:x:/bin/rksh
t2:x:/bin/csh

5 comments:

Mei said...

Hi,I came across your blog when I was googling a unix command to show the data size on my backup tape. It's very impressive! Can you let me know what command I could use? I tried mt status but got 0 files and 0 block, but cpio could output the table of contents on the backuptape. Thank you very much for your help!

esofthub said...

mei, I don't know a command that will do this but I was playing with a tarball file. Here's what I came up with.

tar tvf esofthub.tar | awk '{total+=$3};END {print "Total Size: " total/1024/1024 "MB"}'

I don't have a tape right now to test but you might be able to replace the esofthub.tar with /dev/rmt/0

tar tvf /dev/rmt/0 | awk '{total+=$3};END {print "Total Size: " total/1024/1024 "MB"}'

Thanks for visiting the site.

Mei said...

Thank you for replying to my question! I tried your command, but got an error message: tar taperead error. I think it's because the backup wasn't created by tar. We use cpio to create the backup. Thanks for your help anyway!

Mei said...

Hi,

I just searched all your previous posts on backup procedure, and they are very helpful. Can you talk about how to make a bootable backup of the operating system (Solaris 9 or 10 preferably)? I love this blog!

Mei

esofthub said...

mei, have you read these posts? http://esofthub.blogspot.com/2007/04/install-solaris-boot-block.html
http://esofthub.blogspot.com/2007/04/create-clone-disk-drive.html

You will have to modify the vfstab if the backup disk goes into a different target. I have a disk to disk (ufsdump/ufsrestore) script, too, that I use on occasion. Are you looking for something like that?

Btw, thanks for visiting the blog.