- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: scripting question
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
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
10-03-2002 06:19 PM
10-03-2002 06:19 PM
scripting question
I assume I can use the sort command, but I haven't had much success w/ it.
attached is a sample output of the file. I want to sort on the Serial # column and remove duplicates.
tia,
Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2002 06:23 PM
10-03-2002 06:23 PM
Re: scripting question
but I think it may spit it because some of the across the page do not have anything where others have BCV.
So essentially, some have less fields.
For removing the duplicates, you can use uniq
Scott.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2002 06:29 PM
10-03-2002 06:29 PM
Re: scripting question
I think the best you use Microsoft Excel.
Ftp the file to your PC.
In your PC,
Remove the Headers:
Device Product Device
----------------------- --------- --------------------- ------------------
Name Type Vendor ID Rev Ser Num Cap (KB)
----------------------- --------- --------------------- ------------------
Later you can add them back in.
Open your Ms Excel.
Under File --> Open, choose your .txt file.
After you have successfully import the data, cut & paste the Serial# Column & paste it in the 1st Excel Column
Highlight all the columns.
Under Data --> Sort.
That's it .....
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2002 08:27 PM
10-03-2002 08:27 PM
Re: scripting question
I think there is a little bit difficult to use sort because there are different columns in each row. As I see in your file, there are blank values in the TYPE field and when you using SORT some of the field will shifted.
I'll try my best whether there is any other method to do so or other experts here can do that with SORT ! :)
Regards,
Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2002 09:50 PM
10-03-2002 09:50 PM
Re: scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2002 10:06 PM
10-03-2002 10:06 PM
Re: scripting question
Can you try the following script,
for i in `cut -c57-66
do
grep "$i"
done >
I suggest you to cut off all the header and trailer before you issue this script.
Regards,
Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2002 01:02 AM
10-04-2002 01:02 AM
Re: scripting question
if you want only that column in sort and whitout duplicates try this:
more text_file | grep "^/"|cut -c57-64|sort|uniq
bye
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2002 01:30 AM
10-04-2002 01:30 AM
Re: scripting question
# cat
Will check all lines, so headers, and unrelevant information should be removed. Could do this with grep for example like this:
# cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2002 01:31 AM
10-04-2002 01:31 AM
Re: scripting question
In case procura's script gives syntax errors, try:
perl -ne '1..5 and print,next;$snr=substr($_,56,9);$x{$snr}||=$_;END{for(sort keys%x){print$x{$_}}}'
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2002 01:34 AM
10-04-2002 01:34 AM
Re: scripting question
OTOH it might indeed be good to remomber that not all of you run perl-5.8.0, and certainly not like me with the defined-or patches in :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2002 01:38 AM
10-04-2002 01:38 AM
Re: scripting question
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2002 01:40 AM
10-04-2002 01:40 AM
Re: scripting question
The results go to file "sortedfile"
"sorter" is the source file
echo "HEADER INFO" > sortedfile
for snum in `grep rdsk sorter | cut -c57-64 | sort -u`
do
linedets=`grep ${snum} sorter | head -n1`
lineSnum=`echo "${linedets}" | cut -c57-64`
if [ "$lineSnum" = "$snum" ]
then
echo $linedets >> sortedfile
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2002 04:29 AM
10-04-2002 04:29 AM
Re: scripting question
This is an awk version, inc. a sort routine:
awk 'NR<8{ print }
NR>7 { a[substr($0,56,9)]=$0 }
END {
i=0
for(b in a){
array[i]=b
i++
}
for (j=1;j<=i-1; ++j)
for (k=j;array[k-1]>array[k];--k){
temp=array[k]
array[k]=array[k-1]
array[k-1]=temp
}
for (i=0;i
}
}' filename
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2002 05:26 AM
10-04-2002 05:26 AM
Re: scripting question
You can use the -u option of sort. Or the uniq command.
Sean
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2002 06:11 AM
10-04-2002 06:11 AM
Re: scripting question
I take it that you only want to write out a serial number once, namely for the first occurrence of a number of items sharing the same. That is at least what the attached script does. However, headings are messed up.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2002 12:19 PM
10-04-2002 12:19 PM
Re: scripting question
Correct me if I'm mistaken, but it looks like you're not using PowerPath. If you were, the last three digits of the serial numbers would be unique to each path. It would serve you best to sort on the first five digits.
Use this PERL script:
#!/usr/bin/perl
use strict;
use integer;
our $h={};
our $k;
while(<>){
next if /^\s*$/;
print,next unless m[^/];
@_ = unpack('A23 A10 A22 A18',$_);
@_ = map { (split(/\s+/,$_),undef)[0,1] } @_;
$k = ( $_[2] eq 'EMC' )?substr($_[6],0,5):$_[6];
$h->{$k} = $_ unless defined $h->{$k};
}
foreach $k (sort keys %$h) { print $h->{$k}; }
It breaks up the input line from syminq more than you really need just in case you want to manipulate more than just the serial number. It's probably not the most efficient, but it seems to works.