1753486 Members
4482 Online
108794 Solutions
New Discussion юеВ

Re: AWK Pattern needed

 
Yasmin_1
New Member

AWK Pattern needed

Hi all,

I am using the following array and the pattern to fetch the /etc/vfstab entries,

set -A filesys /TspAcc /TspCore /TspTickets /TspAccBackup /dump /global/TspArchiveLog2
/global/TspArchiveLog1 /global/TspFt /global/TspOam /global/TspTicketpool /opt/SMAW /var /tmp /export/home

position_params=$(nawk -v fsys=${filesys[$i]} ' BEGIN {pat=fsys"^/"}
/^#RMS/ {if ($0 ~ pat) print}
/^[ ]#/ {next}
$0 ~ pat {print}' /etc/vfstab)

eg: for /var filesystem output of above command is

echo $position_params
/dev/md/dsk/d6 /dev/md/rdsk/d6 /var ufs 1 no logging

Can anyone tell me how to fetch line with /(root) entry from the same file with same regular expression..............because now i want to include "/" filesystem in the array but i am unable to get the desired ouput......can anyone help me??


Thanks in advance
9 REPLIES 9
James R. Ferguson
Acclaimed Contributor

Re: AWK Pattern needed

Hi:

This isn't an HP-UX system. Therefore, since I don't have an example '/etc/vfstab' file, I'll use an HP-UX '/etc/fstab' and suggest the following:

# cat ./revised
#!/usr/bin/sh
set -A filesys /TspAcc /TspCore /TspTickets /TspAccBackup /dump /global/TspArchiveLog2 /global/TspAr
chiveLog1 /global/TspFt /global/TspOam /global/TspTicketpool /opt/SMAW /var /tmp /export/home /

i=14

position_params=$(awk -v fsys=${filesys[$i]} 'BEGIN {pat=fsys"^/"}
/^#RMS/ {if ($0 ~ pat) print}
/^[ ]#/ {next}
$2==fsys {print}' /etc/fstab)

echo ${position_params}

...

Notice that I substituted 'awk' for 'nawk' and used '/etc/fstab' instead of '/etc/vfstab'. Then, I added '/' to your shell array.

The essential change is to modify:

$0 ~ pat {print}' /etc/vfstab)

To:

$2==fsys {print}' /etc/fstab)

That is, instead of matching anywhere on the whole line, test a particular _field_ for equality to a string. In HH-UX, in the 'fstab' file, field-2 would by '/' in this case and hence the 14th (i-14) occurance of your array would be the desired match to "root".

Regards!

...JRF...
Yasmin_1
New Member

Re: AWK Pattern needed

Hi ,

Thanks for the quick reply,
But my conerns is i want to search all the entries along with root entry ........
This logic is applicable only to root i want to fetch all the filesystems including root i mentioned and stored the output in a variable.
James R. Ferguson
Acclaimed Contributor

Re: AWK Pattern needed

Hi (again):

> But my conerns is i want to search all the entries along with root entry

Then you might do something along these lines:

# cat ./revisit
#!/usr/bin/sh
filesys="/TspAcc /TspCore /TspTickets /TspAccBackup /dump /global/TspArchiveLog2 /global/TspArchiveL
og1 /global/TspFt /global/TspOam /global/TspTicketpool /opt/SMAW /var /tmp /export/home /"

awk -v fsys="${filesys}" 'BEGIN{n=split(fsys,a," ")}
{for (i=1; i
...which in my case prints the lines in 'fstab' that have matching entries in the "filesys" list.

Regards!

...JRF...
Yasmin_1
New Member

Re: AWK Pattern needed

Hi,

One more thing on one machine some entries starts with #RMS# and i need to fetch even these entries.

But I am getting syntax error for the awk command which you provided now.......could you please help me.


Can't we modify the existing regular expression.

position_params=$(nawk -v fsys=${filesys[$i]} ' BEGIN {pat=fsys"^/"}
/^#RMS/ {if ($0 ~ pat) print}
/^[ ]#/ {next}
$0 ~ pat {print}' /etc/vfstab)


position_params=$(nawk -v fsys=/tmp ' BEGIN {pat=fsys"[^/]*"}
/^#RMS/ {if ($0 ~ pat) print}
/^[ ]#/ {next}
$0 ~ pat {print}' /etc/vfstab)

echo $position_params
swap - /tmp tmpfs - yes -

position_params=$(nawk -v fsys=/var ' BEGIN {pat=fsys"[^/]*"}
/^#RMS/ {if ($0 ~ pat) print}
/^[ ]#/ {next}
$0 ~ pat {print}' /etc/vfstab)
echo $position_params
/dev/md/dsk/d6 /dev/md/rdsk/d6 /var ufs 1 no logging

position_params=$(nawk -v fsys=/ ' BEGIN {pat=fsys"[^/]*"}
/^#RMS/ {if ($0 ~ pat) print}
/^[ ]#/ {next}
$0 ~ pat {print}' /etc/vfstab)

echo $position_params
fd - /dev/fd fd - no - /proc - /proc proc - no - #/dev/md/dsk/d9 /dev/md/rdsk/d9 /globaldevices ufs 2 yes logging /devices - /devices devfs - no - sharefs - /etc/dfs/sharetab sharefs - no - ctfs - /system/contract ctfs - no - objfs - /system/object objfs - no - /dev/md/dsk/d9 /dev/md/rdsk/d9 /global/.devices/node@1 ufs 2 no global /dev/md/dsk/d20 - - swap - no - # /dev/md/oradg/dsk/d14 /dev/md/oradg/rdsk/d14 ocr oracle # /dev/md/oradg/dsk/d12 /dev/md/oradg/rdsk/d12 TSP/rT001.ctrl1_1 oracle # /dev/md/oradg/dsk/d93 /dev/md/oradg/rdsk/d93 TSP/rT001.ctrl1_2 oracle # /dev/md/oradg/dsk/d13 /dev/md/oradg/rdsk/d13 TSP/rT001.ctrl2_1 oracle # /dev/md/oradg/dsk/d94 /dev/md/oradg/rdsk/d94 TSP/rT001.ctrl2_2 oracle # /dev/md/oradg/dsk/d111 /dev/md/oradg/rdsk/d111 TSP/rT001.redo111 oracle # /dev/md/oradg/dsk/d121 /dev/md/oradg/rdsk/d121 TSP/rT001.redo121 oracle # /dev/md/oradg/dsk/d131 /dev/md/oradg/rdsk/d131 TSP/rT001.redo131 oracle # /dev/md/oradg/dsk/d141 /dev/md/oradg/rdsk/d141 TSP/rT001.redo141 oracle # /dev/md/oradg/dsk/d112 /dev/md/oradg/rdsk/d112 TSP/rT001.redo211 oracle # /dev/md/oradg/dsk/d122 /dev/md/oradg/rdsk/d122 TSP/rT001.redo221 oracle # /dev/md/oradg/dsk/d132 /dev/md/oradg/rdsk/d132 TSP/rT001.redo231 oracle # /dev/md/oradg/dsk/d142 /dev/md/oradg/rdsk/d142 TSP/rT001.redo241 oracle # /dev/md/oradg/dsk/d4 /dev/md/oradg/rdsk/d4 TSP/rT001.rollback1 oracle # /dev/md/oradg/dsk/d5 /dev/md/oradg/rdsk/d5 TSP/rT001.rollback2 oracle # /dev/md/oradg/dsk/d3 /dev/md/oradg/rdsk/d3 TSP/rT001.rtp_eventspace oracle # /dev/md/oradg/dsk/d10 /dev/md/oradg/rdsk/d10 TSP/rT001.rtp_indexspace oracle # /dev/md/oradg/dsk/d8 /dev/md/oradg/rdsk/d8 TSP/rT001.rtp_obj_tablespace oracle # /dev/md/oradg/dsk/d9 /dev/md/oradg/rdsk/d9 TSP/rT001.rtp_tablespace oracle # /dev/md/oradg/dsk/d16 /dev/md/oradg/rdsk/d16 TSP/rT001.spfile oracle # /dev/md/oradg/dsk/d7 /dev/md/oradg/rdsk/d7 TSP/rT001.sysaux_1 oracle # /dev/md/oradg/dsk/d91 /dev/md/oradg/rdsk/d91 TSP/rT001.sysaux_2 oracle # /dev/md/oradg/dsk/d6 /dev/md/oradg/rdsk/d6 TSP/rT001.system_1 oracle # /dev/md/oradg/dsk/d90 /dev/md/oradg/rdsk/d90 TSP/rT001.system_2 oracle # /dev/md/oradg/dsk/d11 /dev/md/oradg/rdsk/d11 TSP/rT001.temp_1 oracle # /dev/md/oradg/dsk/d92 /dev/md/oradg/rdsk/d92 TSP/rT001.temp_2 oracle # /dev/md/oradg/dsk/d15 /dev/md/oradg/rdsk/d15 vote oracle /dev/md/dsk/d0 /dev/md/rdsk/d0 / ufs 1 no logging /dev/md/dsk/d3 /dev/md/rdsk/d3 /opt/SMAW ufs 2 yes logging /dev/md/dsk/d6 /dev/md/rdsk/d6 /var ufs 1 no logging /dev/md/dsk/d35 /dev/md/rdsk/d35 /TspAccBackup ufs 2 yes logging /dev/md/dsk/d15 /dev/md/rdsk/d15 /TspAcc ufs 2 yes logging /dev/md/dsk/d40 /dev/md/rdsk/d40 /TspCore ufs 2 yes logging /dev/md/dsk/d25 /dev/md/rdsk/d25 /TspTickets ufs 2 yes logging /dev/md/dsk/d45 /dev/md/rdsk/d45 /dump ufs 2 yes logging /dev/md/arch2dg/dsk/d40 /dev/md/arch2dg/rdsk/d40 /global/TspArchiveLog2 ufs 2 yes global,logging,forcedirectio /dev/md/arch1dg/dsk/d30 /dev/md/arch1dg/rdsk/d30 /global/TspArchiveLog1 ufs 2 yes global,logging,forcedirectio /dev/md/cfsdg/dsk/d10 /dev/md/cfsdg/rdsk/d10 /global/TspFt ufs 2 yes global,logging /dev/md/cfsdg/dsk/d11 /dev/md/cfsdg/rdsk/d11 /global/TspOam ufs 2 yes global,logging /dev/md/cfsdg/dsk/d20 /dev/md/cfsdg/rdsk/d20 /global/TspTicketpool ufs 2 yes global,logging,forcedirectio swap - /tmp tmpfs - yes - /dev/md/dsk/d12 /dev/md/rdsk/d12 /export/home ufs 2 yes logging

I am getting rubbish output for the "/" infact this output
"/dev/md/dsk/d0 /dev/md/rdsk/d0 / ufs 1 no logging"


so can u help to modify the same regular expression or can you give other expression which handles all the above creteria.
James R. Ferguson
Acclaimed Contributor

Re: AWK Pattern needed

Hi (again):

> One more thing on one machine some entries starts with #RMS# and i need to fetch even these entries

Rather than post code and not-quite-right output, please post as a text attachment, an actual copy of your '/etc/vfstab' file and a formatted output sample (of what you want the output to look like). You will need to post twice --- once for each attachment.

Regards!

...JRF...
Yasmin_1
New Member

Re: AWK Pattern needed

Thanks again,

And i have attached the vfstab file in this reply.
Yasmin_1
New Member

Re: AWK Pattern needed

And one more file containing the output.
James R. Ferguson
Acclaimed Contributor

Re: AWK Pattern needed

Hi (again):

OK, using your input file (thanks) try this:

# cat ./reformat
#!/usr/bin/sh
filesys="/TspAcc /TspCore /TspTickets /TspAccBackup /dump /global/TspArchiveLog2 /global/TspArchiveLog1 /global/TspFt /global/TspOam /global/TspTicketpool /opt/SMAW /var /tmp /export/home /"

awk -v fsys="${filesys}" 'BEGIN{n=split(fsys,a," ")}
{for (i=1; i if ($1 ~ /^#RMS/ && $4==a[i]) {print $0;next}
if ($1 !~ /^#/ && $3==a[i]) {print $0;next}
}
}
' /etc/vxfstab
exit 0

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: AWK Pattern needed

Hi Yasmin:

Did you find an acceptable resolution?

If you are happy with the answers, please read the following about assigning points:

http://forums.itrc.hp.com/service/forums/helptips.do?#33

Points are a way of saying "thanks" and adding value to the community by showing future trollers what solved someone else's problem,

Regards!

...JRF...