How to print the first column or last column?

How to print the first column or last column?

Many Linux commands such as the ‘ls’ command generate tabular outputs. Here, we will show you how to print the first column and/or last column from the output of the ‘ls -l’ command. Example 1: Print the first column of a command output The following `awk` command will print the first column from the output of the ‘ls -l’ command.

How to print the first column of a text file in Linux?

When you work with a text file that contains tabular data and want to print the data of a particular column, then the `awk` command is the best option. In this tutorial, we will show you how to print the first column and/or last column of a line or text file. Many Linux commands such as the ‘ls’ command generate tabular outputs.

How to print lines where a field matches?

The default action of awk when in a True condition is to print the current line. Since $2 == “LINUX” is true whenever the 2nd field is LINUX, this will print those lines in which this happens. In case you want to print all those lines matching LINUX no matter if it is upper or lowercase, use toupper () to capitalize them all:

Is the customer name printed as the first column?

Therefore, the customer’s name and id are printed as the first column. If you want to print the customer’s name without the id, then continue to the next example. If you want to print the customer’s name without the id, then you have to use ‘-‘ as a field separator.

How to print the first column or last column or using ` AWK?

The following `awk` command will print the last column from the output of the ‘ls -l’ command. The following output will be produced after running the above commands. The following `awk` command will print the first and last columns from the output of the ‘ls -l’ command.

How to get the first column of Comm output?

However, if you have no choice but to process a pre-run output of comm then as Carl mentioned, cut would be an option: However, this result in empty lines for cases where column 1 is empty. To deal with this, perhaps awk may be more suitable: cut (1) is probably a better choice than awk for this problem.