- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Get a particular column value
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
Forums
Discussions
Discussions
Discussions
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
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
04-07-2006 04:03 AM
04-07-2006 04:03 AM
Get a particular column value
How to get a particular column value from a
file or from output of another command.
See attached sample file.
We use autosys(scheduler program) for scheduling jobs (calls shell scripts).
we issue a command in unix to see status of a autosys job like ,
autorep
and it returns the info as in the attached file.
My Requirement is to ... check this file
and see whether there are any failures ..
which i can get by manually reading the values in the 4th column (ST - status)...it would say SU for success , FA for failure , RU for running etc...
Now i CANT just scan for 'FA' cos some jobnames also has 'FA' in them. I want to know how to get the values of 4th column alone and check for 'FA' in them and report back with
jobname and status.
Points to note.
1) lines are not alligned properly (not sure whthr this matters)
2) in header 4th column is ST but from next line 4th column is date value.
may be a wild thought ..how to read a line from backwards (so that status column is always 3rd)
HELP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 04:17 AM
04-07-2006 04:17 AM
Re: Get a particular column value
autorep
(the print variable 4 is meant for the fourth column. you can tweak its value to see if you are getting the correct column. Then when grep searches for FA it will show it to you on the command line).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 04:21 AM
04-07-2006 04:21 AM
Re: Get a particular column value
awk '{ if (NF > 2) print $(NF - 2) }' < infile
If you want to capture that in a shell variable then:
typeset DT=""
awk '{ if (NF > 2) print $(NF - 2) }' < infile | while read DT
do
echo "Date = ${DT}"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 04:28 AM
04-07-2006 04:28 AM
Re: Get a particular column value
statuscode=`autorep job | awk 'NR=3{print $6}'`
Then you can check statuscode.
if [[ $statuscode = "SU" ]] ; then ...
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 05:37 AM
04-07-2006 05:37 AM
Re: Get a particular column value
statuscode=`autorep job | awk 'NR=3{print $6}'`
if you refer to previously attached sample file...your code prints properly for
lines 3 to 6....line 7 & 9 prints blanks and 8 & 10 prints last column. so it changes dynamically.
AC CLAY
awk '{ if (NF > 2) print $(NF - 2) }' < infile
I'm sorry , its not always going to be 3rd column from last.. if you refer to
previously attached sample file.."SU" (in data records) is in 2nd column from last.
but when there is some value in RUN column then thats going to move to 3rd column.
so it changes dynamically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 05:58 AM
04-07-2006 05:58 AM
Re: Get a particular column value
it seems there are no spaces, and certainly not " FA " to be expected in the jobname.
Given your specification so far Clay's solution should work, it looks backwards using awk's NF (number of fields) as the variable.
You coudl make any solution more robust by using the date/time as search anchor:
/\s+\d+:\d+\s+FA\s+/
Using perl or awk you can also readily remember the job name if that was printed on a seperate line. This technique can also be used to make the status column be on a fixed location:
# perl -ne 'chomp; $_ = $prior . $_; $prior = /\d$/? "" : $_; print "$_\n" if / FA /' your-file
enjoy,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 06:48 AM
04-07-2006 06:48 AM
Re: Get a particular column value
Here is an other approach for a shell/awk/perl script.
Read the file.
If you do not see a ":" on the line, then assume it is just the job name.
In that case, just explictly read a next line and add it on.
#perl -ne "$_ .=<> unless /:/; @words=split; print \"$words[@words-2] $words[0]\n\" if /:/" x.tmp
SU TEST_GHT_INPUT_TABLES_B
SU TEST_PRS_acctUCT_UNIT_B
SU TEST_fw_GHT_acctuctunit_f
FA TEST_sh_GHT_facctuctmove_c
FA TEST_sh_trunc_GHT_acctunit_c
RU TEST_sh_load_GHT_FAunit_c
In perl you could also 'unshift' a saved jobname into a short line.
awk example:
$ awk '(NF<2) {x=$1;getline; $0 =x $0} /:/ && (NF > 2){ print $1, $6}' your-file
TEST_GHT_INPUT_TABLES_B SU
TEST_PRS_acctUCT_UNIT_B SU
TEST_fw_GHT_acctuctunit_f SU
TEST_sh_GHT_facctuctmove_c FA
TEST_sh_trunc_GHT_acctunit_c FA
TEST_sh_load_GHT_FAunit_c RU
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 06:59 AM
04-07-2006 06:59 AM
Re: Get a particular column value
If you like the 'awk' approach, you can reference any column (field) from the last in a line (row) thusly:
# echo "a b c d e f"|awk '{if ($(NF-2)~/d/) {print $(NF-2)}}'
In the above example, I want a field that matches "d" only when it is 2-fields removed from the end (NF) of the line.
In 'awk' NF is the number of fields in the last line read.
The assumption is that the field delimiter is whitespace (spaces, tabs). If it were a colon (":"), simply do use the -F":" switch and argument like this:
# echo "AA:BB:CC:DD:EE:FF"|awk -F":" '{if ($(NF-2)~/D/) {print $(NF-2)}}'
...returns
DD
Note that $(NF-2) specifies the contents of the field that is two removed from the end.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 07:24 AM
04-07-2006 07:24 AM
Re: Get a particular column value
n=`autorep job | grep -c " FA "`
if [[ $n -gt 0 ]] ; then
echo "job had failure..."
fi
Since status FA will have a space before and after, we can use grep to look for that text.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 12:04 PM
04-07-2006 12:04 PM
Re: Get a particular column value
# ex inputfile<
> EOF
It uses ex to filter out lines that have the string "FA" in them along with the line above it in-order to capture the jobname if the autosys output is too long and wraps around to the next line. Thereafter awk displays only those lines that either have a single field in them "jobname" or have the string "FA" embedded in it.
cheers!