- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script help
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
09-18-2006 06:11 AM
09-18-2006 06:11 AM
I have the following lines as input:
10:27:01 0 0 0 0 100
1 0 1 0 99
2 3 0 0 97
3 6 1 0 92
I want to format the ouput as:
Ex:
10:27:01-0-1-2-3-0-0-3-6-0-1-0-1-0-0-0-0-100-99-97-92
Thanks!!
Rajim
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2006 06:22 AM
09-18-2006 06:22 AM
Re: script help
# perl -nale 'push @a,join "-", @F;END{print join "-",@a}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2006 06:55 AM
09-18-2006 06:55 AM
Re: script help
Thanks. I just executed your command it kind of worked. but not exactly. Pardon me, I do not know perl.
10:27:01 0 0 0 0 100
1 0 1 0 99
2 3 0 0 97
3 6 1 0 92
I want (2nd row through 4th row coulmn data)
10:27:01-0-1-2-3-0-0-3-6-0-1-0-1-0-0-0-01-100-99-97-92
Your command gives
10:27:01-0-0-0-0-100-1-0-1-0-99-2-3-0-0-97-3-6-1-0-92
Thanks.
Can you suggest me a good book on perl for dummies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2006 08:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2006 03:31 PM
09-18-2006 03:31 PM
Re: script help
That was a horrible problem specification.
>> I want (2nd row through 4th row coulmn data)
Your data suggests you wnat 1st thru 5th unless there is a timestamp, in which case you want 2 - 6
That appears to be a horrible output format.
What if you ever get an other line of data?
Anyway, here is a chunk of perl with can read multiple blocks of your data pattern:
---- input ---
10:27:01 0 0 0 0 100
1 0 1 0 99
2 3 0 0 97
3 6 1 0 92
10:27:23 0 a 0 0 80
1 b 1 0 81
2 c 0 0 82
3 d 1 0 83
--------------- output --------
10:27:01-0-1-2-3-0-0-3-6-0-1-0-1-0-0-0-0-100-99-97-92
10:27:23-0-1-2-3-a-b-c-d-0-1-0-1-0-0-0-0-80-81-82-83
----------- perl ------
while (<>) {
@words = split;
if (/^\d*:\d+:/) {
&myprint;
undef @data;
$line = 0;
$time = shift @words;
}
$col = 0;
while (defined ($x = shift @words)) {
$data[$line][$col++] = $x;
}
$line++;
}
&myprint;
sub myprint {
if ($time) {
print "$time";
for $c (0..4) {
for $l (0..$line-1) {
print '-',$data[$l][$c];
}
}
print "\n";
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2006 03:34 AM
09-19-2006 03:34 AM
Re: script help
this seems to me a simple awk solution:
awk -v col=5 'function out () {
printf dtm;for (j=1;jNF == (col+1) {if(found) out();dtm=$1; for (i=2;i<=NF;i++) a[i-1]=$i;found++}
NF == col {for (i=1;i<=NF;i++) a[i]=a[i]"-"$i}
END {if(found) out()}' output-file
For customization, set
awk -v col=5 ...
to the appropriate value. Multiple blocks (starting with an additional date field) are processed and reported.
Lines not containing col or (col+1) columns are ignored.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 04:11 AM
09-20-2006 04:11 AM
Re: script help
I will be submitting points soon.