1828959 Members
2119 Online
109986 Solutions
New Discussion

parsing

 
SOLVED
Go to solution
andi_1
Frequent Advisor

parsing

Hi guys,

sometimes, I will have the following entry in the fstab file.

/dev/vgora2/dat2 /mnt/sprd/dat2 vxfs delaylog,mincache=direct,convosync=direct,nodatainlog 0 2

I want to write a script, so when I encounter similar entry as above, I want to endup only with the following info:

dev/vgora2/dat2 /mnt/sprd/dat2 vxfs dev/vgora2/dat2 /mnt/sprd/dat2 vxfs 0 2

What is the best way to do it?

Thanks a bunch!
3 REPLIES 3
Rodney Hills
Honored Contributor
Solution

Re: parsing

Although perl would be good, awk might be simpler-

awk '{print $1,$2,$3,$1,$2,$3,$5,$6}'
awk automatically splits lines up on space/tab and you can reference the "fields" and print them in what ever order.

-- Rod Hills
There be dragons...
Sridhar Bhaskarla
Honored Contributor

Re: parsing

Hi Andi,

sed 's/delaylog,mincache=direct,convosync=direct,nodatainlog//' /etc/fstab > /etc/fstab.new

Verify /etc/fstab.new and move it as /etc/fstab after taking a copy of /etc/fstab.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: parsing

I suggest that you make a slight improvement to Rodney's awk script and test that this is actually a vxfs entry; you probably don't want swap entries. You might want hfs but the fix should be obvious.

awk '{if ($3 ~ /vxfs/){print $1,$2,$3,$1,$2,$3,$5,$6}}'
If it ain't broke, I can fix that.