How to concatenate files containing columns of data in Linux

Ever wondered how to concatenate text files containing columns next to each other ?

One little bash trick which can help you do this the easy way:

Assume you have for example three files containing something like this:

file1.txt

a    b    c

a    b    c

a    b    c

a    b    c

 

file2.txt

1    2    3

1    2    3

1    2    3

1    2    3

file3.txt

m    n    p

m    n    p

m    n    p

m    n    p

What we want to achieve is the following result:

a    b    c    1    2    3    m    n    p

a    b    c    1    2    3    m    n    p

a    b    c    1    2    3    m    n    p

a    b    c    1    2    3    m    n    p

You have two options

Option 1: Try to do it in bash and die in pain. This is usually not funny.

Option 2: The easy way, use the command "paste":

[user@host ~]$ paste file1.txt file2.txt file3.txt
a    b    c     1    2    3     m    n    p

a    b    c     1    2    3     m    n    p

a    b    c     1    2    3     m    n    p

a    b    c     1    2    3     m    n    p

 

The command paste will concatenate the files for you

The program have some cool options, like you can set separator, or use the -s option which will cause the following behavior "paste one file at a time instead of in parallel"

Here is an example with the same files:


[user@host ~]$ paste -s file1.txt file2.txt file3.txt

a    b    c             a    b    c             a    b    c             a    b    c

1    2    3            1    2    3             1    2    3             1    2    3

m    n    p          m    n    p            m    n    p            m    n    p

Each row, becomes a new column.

Have fun :)

Broadcom BCM 802.11 linux-sta driver compilation issues

I am using one lenovo netbook, which is coming with Broadcom wireless adapter.
Since I was having performance issues with the open source driver I started using the driver provided by Broadcom:

http://www.broadcom.com/support/802.11/linux_sta.php

On the newer kernel there are two compilation issues which need patching.

The patches provided below are for version 5.100.82.112 of the driver.

The first issue which I hit was the following error during compilation
/usr/src/linux-sta/src/wl/sys/wl_linux.c:396:2: error: unknown field ‘ndo_set_multicast_list’ specified in initializer
/usr/src/linux-sta/src/wl/sys/wl_linux.c:396:2: warning: initialization from incompatible pointer type [enabled by default]
/usr/src/linux-sta/src/wl/sys/wl_linux.c:396:2: warning: (near initialization for ‘wl_netdev_ops.ndo_validate_addr’) [enabled by default]
make[2]: *** [/usr/src/linux-sta/src/wl/sys/wl_linux.o] Error 1
make[1]: *** [_module_/usr/src/linux-sta] Error 2
make[1]: Leaving directory `/usr/src/kernels/3.4.0-1.fc17.i686'

The secon issue is the following error

/usr/src/linux-sta/src/wl/sys/wl_linux.c:43:24: fatal error: asm/system.h: No such file or directory

which is caused by dropping the header asm/system.h in kernel 3.4 in favor of 5 new headers.

More about this can be read here:

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=0195c002



Here is a patch witch fixes both of the issues.


You can download the patch from pastebin:

http://pastebin.com/C8TZ8q88

I am pasting the code in pastebin, because blogger.com has an "incredibly good" editor and I am fighting for half an hour to make it not hiding most of the source code and as you can see he wins :).

place this text in a file and save it

then go in the dirver directory in my case:

cd /usr/src/linux-sta/src/wl/sys/

and run the patch

patch -p0 < /path/where/the/you/saved/the/patchfile.patch

then try to compile as usual

cd /usr/src/linux-sta/
make clean
make install
depmod -a
modprobe wl

Errors when trying to compile tp_smapi on recent kernels (for me on Fedora 16)

Whoever from you who have a ThinkPad laptop and is using tp_smapi kernel module is probably having troubles compiling the module on recent kernels.

I especially experience problems compiling it on Fedora 16 kernel 3.2.7-1.fc16.i686 but as far as I can see, others people have the same issue on Fedora 15 and other distros too.

For the ones who does not know, this module is giving you an interface to the shock sensor which can be used from hdapsd to protect your HDD from shocks and also gives you some very cool features to control the charge/discharge of your battery and presents you some very useful information about the battery, which can be found in /proc and /sys

Now back to the problem.

When I try to compile the kernel module, version tp_smapi-0.40, I get the following error:


===================================================
make -C /lib/modules/3.2.7-1.fc16.i686/build M=/usr/src/tp_smapi-0.40 O=/lib/modules/3.2.7-1.fc16.i686/build modules
make[1]: Entering directory `/usr/src/kernels/3.2.7-1.fc16.i686'
  CC [M]  /usr/src/tp_smapi-0.40/thinkpad_ec.o
/usr/src/tp_smapi-0.40/thinkpad_ec.c:91:8: warning: type defaults to ‘int’ in declaration of ‘DECLARE_MUTEX’ [-Wimplicit-int]
/usr/src/tp_smapi-0.40/thinkpad_ec.c:91:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tp_smapi-0.40/thinkpad_ec.c: In function ‘thinkpad_ec_lock’:
/usr/src/tp_smapi-0.40/thinkpad_ec.c:108:28: error: ‘thinkpad_ec_mutex’ undeclared (first use in this function)
/usr/src/tp_smapi-0.40/thinkpad_ec.c:108:28: note: each undeclared identifier is reported only once for each function it appears in
/usr/src/tp_smapi-0.40/thinkpad_ec.c: In function ‘thinkpad_ec_try_lock’:
/usr/src/tp_smapi-0.40/thinkpad_ec.c:122:23: error: ‘thinkpad_ec_mutex’ undeclared (first use in this function)
/usr/src/tp_smapi-0.40/thinkpad_ec.c: In function ‘thinkpad_ec_unlock’:
/usr/src/tp_smapi-0.40/thinkpad_ec.c:134:6: error: ‘thinkpad_ec_mutex’ undeclared (first use in this function)
/usr/src/tp_smapi-0.40/thinkpad_ec.c: At top level:
/usr/src/tp_smapi-0.40/thinkpad_ec.c:91:8: warning: ‘DECLARE_MUTEX’ declared ‘static’ but never defined [-Wunused-function]
/usr/src/tp_smapi-0.40/thinkpad_ec.c: In function ‘thinkpad_ec_try_lock’:
/usr/src/tp_smapi-0.40/thinkpad_ec.c:123:1: warning: control reaches end of non-void function [-Wreturn-type]
make[3]: *** [/usr/src/tp_smapi-0.40/thinkpad_ec.o] Error 1
make[2]: *** [_module_/usr/src/tp_smapi-0.40] Error 2
make[1]: *** [sub-make] Error 2
make[1]: Leaving directory `/usr/src/kernels/3.2.7-1.fc16.i686'
make: *** [modules] Error 2
===================================================

After some digging I found the solution in one forum thread, and the solution is:

Replace all the occurrences of DECLARE_MUTEX with DEFINE_SEMAPHORE, which, at the time I am writing this, are in files:

thinkpad_ec.c on line 91
tp_smapi.c on line 112

For those of you who want a patch:

------------- cut below this line -------------
--- thinkpad_ec.c.orig  2008-12-16 07:03:06.000000000 +0200
+++ thinkpad_ec.c       2012-03-04 22:58:10.409371153 +0200
@@ -88,7 +88,7 @@
 #define TPC_PREFETCH_JUNK   (INITIAL_JIFFIES+1)   /*   Ignore prefetch */
 
 /* Locking: */
-static DECLARE_MUTEX(thinkpad_ec_mutex);
+static DEFINE_SEMAPHORE(thinkpad_ec_mutex);
 
 /* Kludge in case the ACPI DSDT reserves the ports we need. */
 static int force_io;    /* Willing to do IO to ports we couldn't reserve? */
--- tp_smapi.c.orig     2008-12-16 07:03:06.000000000 +0200
+++ tp_smapi.c  2012-03-04 22:58:22.074334276 +0200
@@ -109,7 +109,7 @@
 #define SMAPI_PORT2 0x4F           /* fixed port, meaning unclear */
 static unsigned short smapi_port;  /* APM control port, normally 0xB2 */
 
-static DECLARE_MUTEX(smapi_mutex);
+static DEFINE_SEMAPHORE(smapi_mutex);
 
 /**
  * find_smapi_port - read SMAPI port from NVRAM
-------------- cut above this line ---------------

Get the text, place it in a file, save the file.
change the directory in the source dir:

cd tp_smapi-0.40

apply the patch

patch -p0 < /path/to/the/file/with/the/patch

you can try "make" now.

Load the module and happy shock protecting :)