I'm trying to come up with over 500 "short and sweet" bash tips tricks. So
far I have 63, but this includes other Linux tricks as well. I'd like to
get more bash "useful" tricks. Anyone have a useful script they'd be
willing to share?
Although TIP 44 below seems useless. I use it a lot for converting text
data in a file to MySQL insert statements; I pivot the text, then, use an
awk script to add in quotes and "insert into ..".
Anyway, hopefully the following will help -- maybe you have something
better?
The following was taken from
http://osdn.dl.sourceforge.net/sourceforge/souptonuts/How_to_Linux_an...
TIP 43:
"cat" the Contents of Files Listed in a File, in That Order.
SETUP (Assume you have the following)
$ cat file_of_files
file1
file2
$ cat file1
This is the data in file1
$ cat file 2
This is the data in file2
So there are 3 files here "file_of_files" which contains the name of
other files. In this case "file1" and "file2". And the contents of
"file1" and "file2" is shown above.
$ cat file_of_files|xargs cat
This is the data in file1
This is the data in file2
TIP 44:
Columns and Rows -- getting anything you want.
Assume you have the following file.
$ cat data
1 2 3
4 5
6 7 8 9 10
11 12
13 14
How to you get everything in 2 columns?
$ cat data|tr ' ' '\n'|xargs -l2
1 2
3 4
5 6
7 8
9 10
11 12
13 14
Three columns?
$ cat data|tr ' ' '\n'|xargs -l3
1 2 3
4 5 6
7 8 9
10 11 12
13 14
What's the row sum of the "three columns?"
$ cat data|tr ' ' '\n'|xargs -l3|tr ' ' '+'|bc
6
15
24
33
27
Thanks,
Mike Chirico
http://souptonuts.sourceforge.net/chirico/index.php