- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script needed to get the lines that has equal ...
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
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
тАО05-06-2004 10:07 PM
тАО05-06-2004 10:07 PM
The attached file contains binary representation of digits 0 to 1023.
ie:
0000000000
0000000001
...to.....
1111111111
Now I want to separate out only the lines that has equal number of 1s and 0s.
Ex:
0000011111
0101100011
Pl. help.
Thanks,
Karthik S S
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 10:11 PM
тАО05-06-2004 10:11 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
1) Did you forgot to attach the file ?
2) Wouldn't be enought to sum the "1" by lines.
Cheers
Nicolas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 10:28 PM
тАО05-06-2004 10:28 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
Thanks,
Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 10:37 PM
тАО05-06-2004 10:37 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
From my earlier thread on FC-AL Addressing:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=549070
Qustion:
A private loop is typically run using a Fibre Channel hub. It can only address 126 devices because private loop uses an 8-bit address. But why only 126 devices? 2^8 = 256
Response:
The Fibre Channel uses an 8b/10b encoding (every 8 data bits are encoded in 10 'transmission bits' onto the wire), so there are potentially 4 different bit patterns to send a 'byte' over the cable. FC tries to make sure that the number of 0s and 1s are equally 'mixed'. This is done for self-clocking and maintaining the DC balance of the receiver. For error detection the receiver counts the number of 0s and 1s to calculate the 'running disparity'. FC_AL requires a negative value at the end of a 'sub-block'.
For some 8-bit values there exist 10-bit pattern that contain strings of zeros or ones that are longer than 5. So, in the end there are only (if I recall correctly) 138 usable 8-bit values, but some of them are reserved to indicate special 'functions' (e.g. fair arbitration on the FC_AL) and the remaining 126 are usable for devices.
From Some Doc on FC Basics:
Disparity
The 8-bit and 10-bit encoded bytes have a property known as disparity. The loop ID and the AL_PA disparity properties can be positive, negative, or neutral. An 8-bit and 10-bit byte has negative disparity if there are more binary ones in the byte than binary zeroes. Conversely, the byte has positive disparity if there are more binary zeroes than ones.
Neutral disparity is when the number of binary ones equals the number of binary zeroes. This is required to eliminate clocking errors between sender and receiver.
---------------------------------
So I just wanted to make sure that there are really only 134 addresses which have the neutral disparity in a 8 bit address space with 8/b encoding.
Thanks,
Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 10:38 PM
тАО05-06-2004 10:38 PM
SolutionYou can do it with awk and the gsub function:
--- s.awk -----
{
line=$0
n_one=gsub("1","x")
n_zero=gsub("0","x")
if (n_one==n_zero)
print(line)
}
---------------
Now make:
awk -f s.awk 100868.null
Hope this helps.
Frank.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 10:44 PM
тАО05-06-2004 10:44 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
script.pl
--------
while (
chomp;
$line=$_;
$line0=$line;
$line1=$line;
$line0=~ s/[^0]//g;
$line1=~ s/[^1]//g;
if (length($line0) == length($line1)) {
print "$line\n";
}
}
--------
then run
perl script.pl < yourfile
regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 10:49 PM
тАО05-06-2004 10:49 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
But still I am confused with the FC-AL Addressing. I am still not convinced why do we get only 126 usable addresses out of 256.
Anyways I will post it back to Storage forums.
Thanks,
Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 10:52 PM
тАО05-06-2004 10:52 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
Thanks,
Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 10:53 PM
тАО05-06-2004 10:53 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
for i in $(cat t)
do
let x=$(echo $i|wc -c)-1
let z=0
let ones=0
let zeroes=0
while [ $z -lt $x ]
do
let z=$z+1
char=$(echo $i|cut -b $z)
[ $char = 1 ] && let ones=$ones+1
[ $char = 0 ] && let zeroes=$zeroes+1
done
echo $i $ones $zeroes
[ $ones = $zeroes ] && echo $i has same number of 1's and 0's
done
Input file needs to be called t as in line 1 (cat t)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 11:00 PM
тАО05-06-2004 11:00 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
Your script works great too ..!! But little slow though as expected.
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 11:04 PM
тАО05-06-2004 11:04 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
BINARY TABLE GENERATOR
http://www.subterrane.com/bintab.shtml
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2004 11:27 PM
тАО05-06-2004 11:27 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
cat file | while read line
do
if [ $(echo $line | sed 's|0||g') = "1111" ]
then
echo $line
fi
done
Same can be done using awk and perl, of course.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-07-2004 02:32 AM
тАО05-07-2004 02:32 AM
Re: Script needed to get the lines that has equal number of 1s and 0s
I had a perl script that answerred a similar question hanging arround. I added a line or two for you. A little overkill but here is a sample output:
perl bits.pl 3
0 000 000 zero=3, one=0, longest=3 (0)
1 001 001 zero=2, one=1, longest=2 (0)
2 002 010 zero=2, one=1, longest=1 (0)
3 003 011 zero=1, one=2, longest=2 (1)
4 004 100 zero=2, one=1, longest=2 (0)
5 005 101 zero=1, one=2, longest=1 (1)
6 006 110 zero=1, one=2, longest=2 (1)
7 007 111 zero=0, one=3, longest=3 (1)
and:
perl bits.pl 8 | grep "e=4" | sort -k 6 | tail -4
15 00F 00001111 zero=4, one=4, longest=4 (1)
30 01E 00011110 zero=4, one=4, longest=4 (1)
60 03C 00111100 zero=4, one=4, longest=4 (1)
120 078 01111000 zero=4, one=4, longest=4 (1)
Script below.
Enjoy...
Hein.
---- bits.pl ---
$w = shift or die "How many bits wide?";
while ($i < (1<<$w)) {
$zero = $one = $long = $longest = $n = 0;
$last = 2;
$tmp = $i;
while ($n++ < $w) {
$bit = $tmp & 1;
$tmp >>= 1;
if ($bit) { $one++ } else { $zero++ }
$long++ if ($bit == $last);
if ($long > $longest) { $longest = $long; $long_last = $last};
if ($bit != $last) { $last = $bit; $long = 1 };
# print "bit=$bit, last=$last, zero=$zero, one=$one, longest=$longest, ll=$long_last\n";
}
printf ("%4d %03X %.*b zero=%d, one=%d, longest=%d (%d)\n",
$i,$i,$w,$i,$zero,$one,$longest,$long_last);
$i++;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-07-2004 02:59 AM
тАО05-07-2004 02:59 AM
Re: Script needed to get the lines that has equal number of 1s and 0s
"But still I am confused with the FC-AL Addressing. I am still not convinced why do we get only 126 usable addresses out of 256."
If all 256 possible 8-bit bytes are dispatched to the 8b/10b encoder only 134 imerge with neutral disparity. Out of this 7 are used by Fibre Channel for special purpose and what remains is 127 and only that can be used as ALPA because ALPA requires neutral disparity. Again 1 goes for FL_port and 126 remains for NL_ports.
For more details refer:
:Designing Storage Area Networks:
By Tom Clark
Chapter 4. Page 53/54
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-07-2004 03:09 AM
тАО05-07-2004 03:09 AM
Re: Script needed to get the lines that has equal number of 1s and 0s
But do you have a table that maps 8 bit characters to a 10 bit encoded characters?? I want understand how they calculate 8/10b encoding.
Thanks,
Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-07-2004 03:33 AM
тАО05-07-2004 03:33 AM
Re: Script needed to get the lines that has equal number of 1s and 0s
Basically 8b/10b coding was used to cope with high speed (Gigabit) transmission. This is because hex FF (1111 1111) would appear as a sustained DC positive voltage on the line and one cant differentiate between two bits of data.
SO every 8 bit byte that is transmitted will go thr' this encoder so that it is possible to detect when one bit ended and another began.
8b/10b was first developed by IBM and what it does is converts each 8 bit byte into two possible 10 bit characters, one with positive disparity and other with negative. So encoder decides which parity to used depending on the one used for earlier 8 bit byte.It could be positive or negative. If positive is used negative is discarded. This concept is bit confusing but if you know how Arbitration in FC-AL loop works then it is simple to understand.
This encoders are nothing but Firmware sitting on HBA in your Machine. You can compare them with Transciever on NIC.
Made an effort to clear this a bit. Actually this is very big topic and diffcult to mention all related things.
Hope this clear your doubt.
Regards,
Bharat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2004 06:20 AM
тАО05-08-2004 06:20 AM
Re: Script needed to get the lines that has equal number of 1s and 0s
I don't think the arbitration process has anything to do with disparity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2004 06:41 PM
тАО05-08-2004 06:41 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
1. What is ALPA?
2. Primitive Signals like ARB(x), IDLE, ARB(F0), etc.
3. How to differentiate between this Signals?
Along with this it is also important to know loop addressing and loop initialization process.
THis help you understand why such kind of addressing, what primitive signals are and how actual data is diffentiated from control signals.
Uwe, please correct me if am wrong with small desription.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2004 10:46 PM
тАО05-08-2004 10:46 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
Arbitration itself does not care how the data is encoded on the wire. You can also do it on a piece of paper or a board at the wall.
The problem is that FC_AL was tacked on later, so it has to live with some limitations (e.g. not every data byte has a transmission character with neutral disparity or one that can force a negative disparity) - see my response from today at:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=549070
I agree that it is nice to understand why, e.g. 3 cannot be used as an AL_PA, but it is not required for an end-user.
With all those questions it looks like Karthik wants to build his own Fibre Channel equipment ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-09-2004 04:52 PM
тАО05-09-2004 04:52 PM
Re: Script needed to get the lines that has equal number of 1s and 0s
Uwe, I am not joining this game :-)) .. I have no plans of becoming a Fiber Scientist ;-).
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-09-2004 05:13 PM
тАО05-09-2004 05:13 PM