- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Strings from command output
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-12-2006 08:35 PM
04-12-2006 08:35 PM
What is the way to get several strings from some hp-ux command and write them to file?
for example
#more filename
ab
bc
cd
ed
I need to read "ab" and "ed" and write it to filename1.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 08:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 09:14 PM
04-12-2006 09:14 PM
Re: Strings from command output
there are several ways, e.g. grep, assuming the file "filename" is in the current directory:
# grep -E "^ab|^ed" ./filename >newfile
which will match lines beginning with ab or ed
If you want to match the two strings anywhere in a line, then:
# grep -E "ab|ed" ./filename >newfile
But you will probably get many other suggestions!
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 09:15 PM
04-12-2006 09:15 PM
Re: Strings from command output
thank you for advice, I've cheked it, but I need more complex output.
The command is the following
#omnimm -media_info BM2605L1 -detail
MediumID : 0a01010b:412b055d:1f33:0001
Pool name : NW3-Pool
Library : Ultrium
Medium Label : [BM2605L1] NW3-Pool_4
: [Ultrium: 1]
Medium Owner : lev
Used blocks : 470891648
Total blocks : 470891648
Number of writes : 14
Number of overwrites : 15
Number of errors : 0
Creation time : Tue Aug 24 15:07:41 2004
Time of last write : Tue Apr 11 22:02:57 2006
Time of last overwrite : Wed Apr 5 22:37:33 2006
Time of last access : Tue Apr 11 22:02:57 2006
Medium type : FULL
Write-protected : No
I need to get Pool name: Library: Medium Label: Location: into one string, so that every word will be the heading of the separate column. And the value of each parameter acoording to command outpu must be written to column below the heading.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 09:16 PM
04-12-2006 09:16 PM
Re: Strings from command output
thank you for advice, I've cheked it, but I need more complex output.
The command is the following
#omnimm -media_info BM2605L1 -detail
MediumID : 0a01010b:412b055d:1f33:0001
Pool name : NW3-Pool
Library : Ultrium
Medium Label : [BM2605L1] NW3-Pool_4
: [Ultrium: 1]
Medium Owner : lev
Used blocks : 470891648
Total blocks : 470891648
Number of writes : 14
Number of overwrites : 15
Number of errors : 0
Creation time : Tue Aug 24 15:07:41 2004
Time of last write : Tue Apr 11 22:02:57 2006
Time of last overwrite : Wed Apr 5 22:37:33 2006
Time of last access : Tue Apr 11 22:02:57 2006
Medium type : FULL
Write-protected : No
I need to get pframeters Pool name: Library: Medium Label: Location: into one string, so that every parameter will be the heading of the separate column. And the value of each parameter acoording to command output must be written to column below the heading.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 09:28 PM
04-12-2006 09:28 PM
Re: Strings from command output
Try this
$
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 09:42 PM
04-12-2006 09:42 PM
Re: Strings from command output
Based on the sample input you'ave provided...try this awk construct.
# omnimm -media_info BM2605L1 -detail | awk -F: '
> /^Pool name/||/^Library/||/^Medium Label/{head=head" "$1;val=val" "$2}
> END{printf("%s\n%s\n",head,val)}'
I don't see any record that starts with Location so I left it out of the awk pattern, however you can easily extend it.
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 09:50 PM
04-12-2006 09:50 PM
Re: Strings from command output
or as a cumbersome shell script:
#!/usr/bin/sh
omnimm -media_info BM2605L1 -detail > a.dat
grep -f a.grep a.dat > a.rep
while read record
do
heading=`echo $record | cut -d':' -f1`
data=`echo $record | cut -d':' -f2`
heado="${headi}\t$heading"
headi=$heado
datao="${datai}\t$data"
datai=$datao
done < a.rep
echo $headi
echo $datai
where a.grep contains:
Pool name :
Library :
Medium Label :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 10:08 PM
04-12-2006 10:08 PM
Re: Strings from command output
It works perfect!
and the last question:
What expression I must use to get only BM2605L1
from the string
Medium Label : [BM2605L1] NW3-Pool_4
without signs '[' and ']' ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 10:10 PM
04-12-2006 10:10 PM
Re: Strings from command output
This will produce a nicely formatted table:
# omnimm -media_info BM2605L1 -detail | perl -nle 'printf "%-25s %s\n",$1,$2 if /(.+)\s+:\s+(.+)/'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 10:16 PM
04-12-2006 10:16 PM
Re: Strings from command output
I get the same result as the output of command omnimm without any awk expressions. The difference is that using your example I get the same outpur but without ':' sign.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 10:17 PM
04-12-2006 10:17 PM
Re: Strings from command output
based on sandman:
# omnimm -media_info BM2605L1 -detail | awk -F: '
> /^Pool name/||/^Library/||/^Medium Label/{head=head" "$1;if ($2 ~ "]") add=substr($2,2,length($2)-2)
else add=$2
val=val" "add}
> END{printf("%s\n%s\n",head,val)}'
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 10:20 PM
04-12-2006 10:20 PM
Re: Strings from command output
you can cut your string like this:
# LABEL="Medium Label : [BM2605L1] NW3-Pool_4"
# REMOVE_START=$(echo ${LABEL##Medium Label : \[})
# echo ${REMOVE_START%%\]*}
BM2605L1
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 10:29 PM
04-12-2006 10:29 PM
Re: Strings from command output
but how to get this result from omnimm output that I provided above?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 10:33 PM
04-12-2006 10:33 PM
Re: Strings from command output
# omnimm -repository_barcode_scan Ultrium
[Normal] From: UMA@lev "Ultrium" Time: 04/13/06 14:26:48
STARTING Media Agent "Ultrium"
[Normal] From: UMA@lev "Ultrium" Time: 04/13/06 14:26:53
COMPLETED Media Agent "Ultrium"
[Normal] From: MSM@lev "Ultrium" Time: 04/13/06 14:26:53
Slot [side] Medium type Medium Label (ID)
===============================================================================
1 Data Protector [BM2605L1] NW3-Pool_4
2 Data Protector [BM2609L1] DMProd-Pool_1
3 Data Protector [BM2584L1] DMProd-Pool_3
4 Data Protector [BM2592L1] PRS-Week_3
5 Data Protector [BM2606L1] NW3-Pool_1
6 Data Protector [BM2572L1] SRD-Week_2
7 Data Protector [BM2573L1] DMTest-Pool_1
8 Data Protector [BM2571L1] DMTest-Pool_2
9 Data Protector [BM2574L1] NW3-Pool_2
10 Data Protector [BM2570L1] NW3-Pool_3
11 Data Protector [BM2595L1] NPU_6
12 Data Protector [BM2616L1] NW2-Pool_4
13 Data Protector [BM2617L1] NPU_1
14 Data Protector [BM2618L1] Ignite_Pool_3
15 Data Protector [BM2647L1] NW3-Pool_5
16 Data Protector [BM2619L1] Ignite_Pool_2
17 Data Protector [BM2625L1] MFS-Pool_7
18 Data Protector [BM2599L1] MFS-Pool_6
19 Data Protector [BM2627L1] NW2-Pool_2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 11:11 PM
04-12-2006 11:11 PM
Re: Strings from command output
assuming the file infile2 holds the BM***s, you can try this:
# cut -d" " -f ,4 ./infile2| tr -d [\[\]]
alternatively, you can read through the file one line at a time:
#!/usr/bin/sh
while read a b c d e
do
REMOVE_START=${d#\[}
echo ${REMOVE_START%\]}
done<$1
run it like this:
# abovescript.sh infile2
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 11:41 PM
04-12-2006 11:41 PM
Re: Strings from command output
you can use this:
awk '$4 ~ "[[]BM" {print substr($4,2,length($4)-4)}' filename
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 11:43 PM
04-12-2006 11:43 PM
Re: Strings from command output
awk '$4 ~ "[[]BM" {print substr($4,2,length($4)-2)}' filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2006 11:53 PM
04-12-2006 11:53 PM
Re: Strings from command output
My apologies for my first post. I read your requirements too quickly. With regard to "...how to get only all BM**** from this output...":
# perl -nle 'print $1 if /\[(BM.+)\]/' datafile
(or):
#
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2006 04:33 PM
04-13-2006 04:33 PM