4
1
I have a file that contains:
1 2 3 4
1 3 5 4 8
3 2 1
Each line has a different number of digits. And there are 1000 more like this.
I want the output like this:
1 2
2 3
3 4
4 0
1 3
3 5
5 4
4 8
8 0
3 2
2 1
1 0
edit made to this post!!
i mean if this is last digit in line put that digit and then zero besides it.
for example if digit is last in that line we put in output new line that digit and zero
4 0 and others:see output sample tnx
in above example and
How can I do that, in perl
awk
or bash
i use this but its not working :((
awk '{
for (i=1; i<NF; i++)
{
if ( $(i+1) == "")
print $i, "0"
else
print $i, $(i+1)
}
}' UniqASinline> inTestAst
the outpute file of Mr.glenn jackman way:
for this imput:
3549
3549 10026
3549 10026 10010
3549 10026
awk '{for (i=1; i<=NF; i++) printf("%d %d\n", $i, $(i+1))}' filename
3549
3549 10026
10026
3549 10026
10026 10010
10010
3549 10026
10026
but we expect:
3549 0
3549 10026
10026 0
3549 10026
10026 10010
10010 0
3549 10026
10026 0
tnx
Sounds like a homework =) – Gilles Quenot – 2012-12-19T19:38:01.743
i can do it by sending item into array and then process the array but if we have 1000 lines its too slow in bash :(( !!!! – Arash – 2012-12-19T19:42:16.667