Example:
Code: Select all
$ cat > file1.txt
id
1
2
3
4
5
$ cat > file2.txt
value
foo
bar
baz
egg
sax
$ paste ./file{1,2}.txt
id value
1 foo
2 bar
3 baz
4 egg
5 sax
Example:
Code: Select all
$ cat file1.txt
Name:
John
Anna
Josh
Dick
Hope
$ cat file2.txt
TEL:
555-456123
555-987654
555-668844
555-997733
555-147852
$ cat file1.txt | nl # number rows example
1 Name:
2 John
3 Anna
4 Josh
5 Dick
6 Hope
$ cat file1.txt | nl > file_A
$ cat file2.txt | nl > file_B
$ join -1 1 -2 1 file_{A,B} # join by first field from "left" file [-1 1] and by first field from "right" file [-2 1]
1 Name: TEL:
2 John 555-456123
3 Anna 555-987654
4 Josh 555-668844
5 Dick 555-997733
6 Hope 555-147852
- cut [-d --- specifies delimiter, default tab; -f --- fields to output ]
awk [-F --- specifies delimiter, default white space(tab, space); $# --- fields to output ]
Code: Select all
$ echo -e "1|2|3|4|5|6\na|b|c|d|e|f"
1|2|3|4|5|6
a|b|c|d|e|f
$ echo -e "1|2|3|4|5|6\na|b|c|d|e|f" | cut -d"|" -f3-5
3|4|5
c|d|e
$ echo -e "1|2|3|4|5|6\na|b|c|d|e|f" | awk -F"|" '{print $3"-"$4"-"$5}'
3-4-5
c-d-e