lunes, 12 de julio de 2010

Wasn't there a command to do XYZ?...

At $work, many times I'm asked about ways to optimize little annoying processes of other people (I'm a kind of office enabler).

There's a typical dialog of some $coworker, and $self.

- Hey Rai, I've got a little question for you.
- Ok, go on.
- Wasn't there a linux command to put lines of two files in one file, one line after the other? Like a columnwise join.
- M... yeah... I think so. Was it 'join'? Nah, man doesn't seem to say anything about it... Well, you can use Perl, you know, the swiss knife.
- Yeah, but I don't think a script is needed, For now, I'm doing it with excel, you can copypaste each file in different columns, and then save as CSV, then you just have to remove the commas, using vim.
- ¬_¬ .... Gimme 30 secs.

echo 'a' >a
echo 'a' >>a
echo 'a' >>a
echo 'b' >b
echo 'b' >>b
echo 'b' >>b
perl -e 'open $a,shift;open $b,shift; while(chomp($_=<$a>)){print $_, scalar(<$b>)}' a b

output:
ab
ab
ab