Display two files side by side
You can use pr
to do this, using the -m
flag to merge the files, one per column, and -t
to omit headers, eg.
pr -m -t one.txt two.txt
outputs:
apple The quick brown fox..
pear foo
longer line than the last two bar
last line linux
skipped a line
See Also:
- Print command result side by side
- Combine text files column-wise
BASH: Display two files side by side simultaneously
This works fine
paste "$FILE1" "$FILE2" | awk -F'\t' '{printf("%-16s%s\n", $1, $2)}'
Compare and display two files side by side
Here's the general approach:
$ cat tst.awk
NR==FNR{ a[$1] = $2; next }
{ a[$1]; b[$1] = $2 }
END {
for (key in a) {
printf "%-10s%-15s%-15s\n", key, a[key], b[key]
}
}
$ awk -f tst.awk A.txt B.txt
LName LastName
Phone 00-1234567
Mobile1 000-000-000
EMail user1@aol.com user2@aol.com
EmpID 1234 2345
FName User1 User2
You'd need to provide the logic for how a script would know to output "FName" before "LName", "Mobile1" comes before rather than after "Phone" and the order of the other fields in your output if you care about that. One possibility would be to hard-code the keys:
$ cat tst.awk
BEGIN{ split("FName LName EmpID Mobile1 Phone Email", keys) }
NR==FNR{ a[$1] = $2; next }
{ b[$1] = $2 }
END {
for (keyNr=1; keyNr in keys; keyNr++) {
key = keys[keyNr]
printf "%-10s%-15s%-15s\n", key, a[key], b[key]
}
}
$ awk -f tst.awk A.txt B.txt
FName User1 User2
LName LastName
EmpID 1234 2345
Mobile1 000-000-000
Phone 00-1234567
Email
Xcode - How to view two files side-by-side?
Xcode 11 and above (thanks for the update, @Uthen!)
Click on the Add Editor on Right button in the top right corner of the editor:
To add an editor to the bottom instead, hold down the Option key while pressing the button, it will change to Add Editor Below:
If you want to choose a different file to show, navigate to a different file using the folder buttons above the editor:
Xcode 10 and earlier
Simply click on the button in the top right corner with two overlapping circles to access it or navigate to View/Assistant Editor/Show Assistant editor (⌥⌘^↩).
If you want to choose a different file to show, click on the button right to the navigation arrows in the right side of the screen and select an option from the context menu. Choose Manual to pick any file you want.
If you want to change the layout to horizontal/vertical, navigate to View/Assistant Editor and change the view. Here, you can also add and remove new assistant editors if display more than two files at the same time.
concat two files side-by-side, append difference between fields, and print in tabular format
Your awk command seems fine except -F,
. You should paste
those files first.
$ paste a.txt b.txt | awk '{print $0,$3-$6}' | column -t
a 2019 66 a 2019 50 16
b 2020 50 b 2019 40 10
c 2018 48 c 2018 45 3
What's clean way to join two files together side by side?
Use paste
:
paste A B
That will separate the lines from A and the lines from B with a tab character. If you want them separated with a space instead, use
paste -d' ' A B
Python how do I print the contents of 2 or more text files side by side?
You can use the format
method in builtin strings, and zip_longest
.
from itertools import zip_longest
...
# Assuming fruit is file_context.readlines()
fruits = fruit.split("\n")
vegs = veg.split("\n")
for l1,l2 in zip_longest(fruits, vegs, fillvalue=""):
print("{}\t{}".format(l1, l2))
zip_longest
will take care of the situation where you have unequal number of fruits and vegs.
NOTE: The above will work in python 3. For python 2, remember to replace:
from itertools import zip_longest
with:
from itertools import izip_longest
View multiple files in Visual Studio
You can use "Tab Groups". Visual Studio supports both horizontal and vertical panes (since at least Visual Studio .NET 2002 I believe, I haven't used VS 5 or 6 in ages..)
There are several ways to create a tab group. One way is:
- Open two files.
- Grab the tab of one of the files and pull it down and slightly to the side
- You'll get a menu prompting you if you want to put it in a new horizontal or vertical pane.
- You can move files between panes by grabbing the tab of the open file and pulling it next to the tabs in the pane you want it in.
Another way is:
- Click Window
- Click New Vertical Tab Group
Here is a website demonstrating this with pictures and it even includes showing you how to split pane with the same file. Handy when refactoring!
Related Topics
How to Run Nginx Within a Docker Container Without Halting
Vim Configuration for Linux Kernel Development
How to Edit /Etc/Sudoers from a Script
Get Yesterday's Date in Bash on Linux, Dst-Safe
"In-Source Builds Are Not Allowed" in Cmake
Does Gcc Have Any Options to Add Version Info in Elf Binary File
Linux Vi Arrow Keys Broken in Insert Mode
Converting Serial Port Data to Tcp/Ip in a Linux Environment
Removing Part of a Filename for Multiple Files on Linux
How to Tell Linux Not to Swap Out a Particular Processes' Memory
Replace Whitespace with a Comma in a Text File in Linux
Colour Highlighting Output Based on Regex in Shell
Running Shell Script in Parallel
How to Compile Glut + Opengl Project with Cmake and Kdevelop in Linux