Data manipulation from one file

HI all

i have a file consisting of following numbers

0000
0000
0000
0000
0000
1010
0000
0100
0000
0000
0000
1111
0000
1010
0000
0100
0000
0000
0000
0000
1010
0000
0000
0100

I want to have an output in such a way that it will consist these two fields separated by a tab or :
(First Number || Third Number)
(Sec. Number || Fourth Number)

e.g
for input 1010
the output should be 1 0

for input 1001
the output should be 1 1

and the third file should consist the decimal equivalent of the number stored in second file

i.e for 10 it should be 2
for 11 it should be 3

I can't understand what you mean.

every line has four numbers
so i need to apply the logic as i mentioned over there

i.e if line has a number like 1011
so i need to make or operation of two numbers in same color above
1 || (OR) 1 gives 1
0 || (OR) 1 gives 1

like this
so the o/p will be 11
and finally 11 (binary) = 3 (decimal)

try this,"file" is the input file

 sed 's/\(.\)/\1 /g' file | awk '{a=$1||$3;b=$2||$4;printf "%d%d(binary)=%d(decimal)\n",a,b,a*2+b}'
1 Like