- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need help on AWK Script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 01:54 AM
тАО02-05-2009 01:54 AM
Need help on AWK Script
Can some one help me.
I have ouput as below:
/celcomdb17/oradata/Celcom/CDR16.dbf
/celcomdb17/oradata/Celcom/INDEX_32K/32K_CCOLL_COUNTERIND44.dbf
I would like to truncate/chop the last field.
The output shout be
/celcomdb17/oradata/Celcom
/celcomdb17/oradata/Celcom
Please assist.
TQ
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 02:14 AM
тАО02-05-2009 02:14 AM
Re: Need help on AWK Script
$ cat RMAN_policy.sh
#! /bin/ksh
#
# set command line variables
#
PATH=/usr/openv/netbackup/bin:/usr/openv/netbackup/bin/admincmd:/usr/openv/netbackup/bin/goodies:/usr/openv/netbackup/bin/goodies/support:/usr/openv/volmgr/bin:/usr/openv/volmgr/bin/goodies:/opt/VRTSvxfs/sbin:$PATH
#USAGE="USAGE: RMAN_policy.sh
#shift `expr $OPTIND - 1`
#INSTANCE=$1
#SERVER=$2
#PRIORITY=$3
#VPOOL=$4
#BPATH=$5
#OSV=$6
#PASSES=`wc -l $1 | awk '{ print $1 }'`
#PASSNO=0
function while_read_LINE
{
cat $1 | while read LINE
do
echo "$LINE"
INSTANCE=`echo "$LINE" | awk '{ print $1 }'`
SERVER=`echo "$LINE" | awk '{ print $2 }'`
PRIORITY=`echo "$LINE" | awk '{ print $3 }'`
VPOOL=`echo "$LINE" | awk '{ print $4 }'`
BPATH=`echo "$LINE" | awk '{ print $5 }'`
OSV=`echo "$LINE" | awk '{ print $6 }'`
echo "$INSTANCE"
echo "$SERVER"
echo "$PRIORITY"
echo "$VPOOL"
echo "$BPATH"
echo "$OSV"
echo bppolicynew ora_"$INSTANCE"
echo bpplinfo ora_"$INSTANCE" -set -ut -active -blkincr 0 -collect_tir_info 0 -compress 0 -crossmp 1 -disaster 0 -encrypt 0 -follownfs 0 -multiple_streams 1 -policyjobs 0 -pool "$VPOOL" -priority "$PRIORITY" -pt Standard -residence foo -chkpt 1 -chkpt_intrvl 30
echo bpplsched ora_"$INSTANCE" -add Full
echo bpplschedrep ora_"$INSTANCE" Full -cal 0 -freq 86400 -mpxmax 1 -rl 5 -st FULL
echo bpplinclude ora_"$INSTANCE" -add "$BPATH"/*
echo bpplclients ora_"$INSTANCE" -add "$SERVER" Solaris "$OSV"
#PASSNO=`expr $PASSNO + 1`
#echo END PASS "$PASSNO"
#INSTANCE=$INSTANCE; shift 6
#SERVER=$SERVER; shift 6
#PRIORITY=$PRIORITY; shift 6
#VPOOL=$VPOOL; shift 6
#BPATH=$BPATH; shift 6
#OSV=$OSV; shift 6
done
}
$
From:
http://www.unix.com/shell-programming-scripting/85239-parsing-file-line.html
Or:
http://cdunix.blogspot.com/2008/09/parsing-connectdirect-stats-part-2_26.html
awk is great for breaking up strings using field separators.
/ is a special character, requires a little more work.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 02:17 AM
тАО02-05-2009 02:17 AM
Re: Need help on AWK Script
> I would like to truncate/chop the last field
# awk -F/ '{OFS="/";print $1,$2,$3}' file
...would yield the output you requested.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 02:23 AM
тАО02-05-2009 02:23 AM
Re: Need help on AWK Script
I am not sure I undersxtand what you want.
If you truncate the last "field" from
/celcomdb17/oradata/Celcom/INDEX_32K/32K_CCOLL_COUNTERIND44.dbf
... it should be:
/celcomdb17/oradata/Celcom/INDEX_32K
... not as you said in the original message.
So, if you really want the last
"slash-separated" field to be removed,
it is as simple as:
for i in /celcomdb17/oradata/Celcom/CDR16.dbf
/celcomdb17/oradata/Celcom/INDEX_32K/32K_CCOLL_COUNTERIND44.dbf
do
dirname $i
done
The result is:
/celcomdb17/oradata/Celcom
/celcomdb17/oradata/Celcom/INDEX_32K
Please clarify your requirements.
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 02:24 AM
тАО02-05-2009 02:24 AM
Re: Need help on AWK Script
Second try:
[root@bersheva ~]# F1="/steve/direname1/file.dbf"
[root@bersheva ~]# d1=$(echo $F1 | awk -F "/" '{ print $1}')
[root@bersheva ~]# echo $d1
[root@bersheva ~]# d1=$(echo $F1 | awk -F "/" '{ print $1 }')
[root@bersheva ~]# echo $d1
[root@bersheva ~]# d1=$(echo $F1 | awk -F "/" '{ print $2 }')
[root@bersheva ~]# echo $d1
You can go forward from here.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 03:46 AM
тАО02-05-2009 03:46 AM
Re: Need help on AWK Script
Appology my typo.
Actually output should be :
/celcomdb17/oradata/Celcom
/celcomdb17/oradata/Celcom/INDEX_32K
The OFS "/" length is varried.
I would like to get only directory.
Thanks
-Kamarul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 03:52 AM
тАО02-05-2009 03:52 AM
Re: Need help on AWK Script
See "man dirname" for more information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 04:04 AM
тАО02-05-2009 04:04 AM
Re: Need help on AWK Script
> I would like to get only directory
Well, that makes it clear, now.
Use the 'dirname' function as VK2COT suggested, or skip spawning this process and let the shell do all the work:
# cat mylist
/celcomdb17/oradata/Celcom/CDR16.dbf
/celcomdb17/oradata/Celcom/INDEX_32K/32K_CCOLL_COUNTERIND44.dbf
# while read DIR
do
echo ${DIR%/*}
done < mylist
/celcomdb17/oradata/Celcom
/celcomdb17/oradata/Celcom/INDEX_32K
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 04:10 AM
тАО02-05-2009 04:10 AM
Re: Need help on AWK Script
based on Mr. Ferguson's first suggestion:
$ awk -F/ '{OFS="/"; $NF="";print substr($0,1,length($0)-1)}' < yourinputfile
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-06-2009 01:37 AM
тАО02-06-2009 01:37 AM
Re: Need help on AWK Script
dirname is the command for you:
dirname /celcomdb17/oradata/Celcom/CDR16.dbf
/celcomdb17/oradata/Celcom/
HTH,
Art