Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Check the paste command. You have to specify a null delimiter using the -d option, since the default one is TAB. Also you have to remove the extra dot from the end of the first file or from the beginning of the second one. Suggestion using process substitution:
Here's one using only Bash internal functions (meaning no programs from outside Bash itself). I couldn't think of any way to do it in a single loop, so I leave that as an exercise for the reader.
Code:
foo$ t="$IFS"; IFS=.; i=0; while read a b c; do l[++i]="$a.$b.$c"; done < file1; IFS="$t"; i=0; while read d; do echo "${l[++i]}$d"; done < file2
10.1.1.1
10.1.2.2
10.1.3.3
foo$
@grail - my code does work; check it out. The rationale is that, from the example, it is obvious that "file 2" echoes the final column of "file 1", therefore, it is unnecessary to call "file 2" as the output from "file 2" is already embedded in "file 1".
@Trickie - ok ... I will concede that with your rationale this specific example works, but based on the fact that the OP says he has 2 files to be joined, it seemed obvious that this was a simple
example to help illustrate the point. Assuming your version, you could simply do:
@grail - err, no you can't. There are two errors: it doesn't save into a third file, which "noony123" asked for and secondly, your code produces no "dot" as a field separator between the third and fourth fields, again, as "noony123" requested.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.