Skip to content
Home ยป Blog ยป Bash Script: Merge lists

Bash Script: Merge lists

I see you copy&pasting your scraped lists together ๐Ÿ‘€

Just joking. I’m sure you figured that out.

I want to give you a little script for doing that anyway. Also to help the people who are really just getting started into this.

Again, a great example on how some scripting skills can save you time and money. No searching on the internet for a tool, no interruption in your building process. Imagine you found a tool that merges three lists, but now you want to merge five and that tools can only do three…

Anyway, a word about the script. Nested loops are never good. But this is only for one time use. We will most likely never work on the script again. So please forgive me the poor coding style.

Here’s the little script (save it as for example):


for LINE1 in `cat $1`
    for LINE2 in `cat $2`
	for LINE3 in `cat $3`
		echo $LINE1 $LINE2 $LINE3

Run it like this:

./ list1.txt list2.txt list3.txt >output.txt

Again, don’t forget to make it executable first:

chmod +x

Have fun.

Leave a Reply

Your email address will not be published. Required fields are marked *