PDA

View Full Version : [ubuntu] how to duplicate each line of stdin



cthlhu1987
November 4th, 2009, 05:08 PM
How to duplicate the stdin like this:
before:

foo
bar
baz
quz

after:

foofoo
barbar
bazbaz
quzquz

diesch
November 4th, 2009, 05:12 PM
sed -res'/(.*)/\1\1/'

Giblet5
November 4th, 2009, 05:13 PM
awk '{ printf("%s%s\n", $1, $1); }'

diesch
November 4th, 2009, 05:19 PM
awk -F\$ '{print $1$1}'

Giblet5
November 4th, 2009, 05:44 PM
cat > foofoo.c << !
#include <stdio.h>
#include <string.h>

int main()
{
char bp[1024];
while(fgets(bp, 1023, stdin)) {
while(bp[strlen(bp)-1] == '\n') bp[strlen(bp)-1] = '\0';
if(!strlen(bp)) break;
printf("%s%s\n", bp, bp);
}
return 0;
}
!
gcc -o foofoo foofoo.c
./foofoo

cthlhu1987
November 4th, 2009, 05:47 PM
sed -res'/(.*)/\1\1/'


awk '{ printf("%s%s\n", $1, $1); }'

awk -F\$ '{print $1$1}'
Thx, all 3 variants worked. You rule :popcorn::KS:P:D

leandromartinez98
November 4th, 2009, 06:02 PM
If it was for general file/table editing, you could use vim:

http://www.youtube.com/watch?v=lFUE7BTUHuc

Control-V to select
y to copy
p to paste