Can head display specific columns?

The head command itself does not have the capability to display specific columns from a file. However, you can combine it with other commands like awk or cut to achieve this.

For example, if you want to display the first 10 lines of a file and only show specific columns, you can use awk like this:

head -n 10 filename.txt | awk '{print $1, $3}'

In this example, $1 and $3 represent the first and third columns of the output.

Alternatively, you can use cut to specify which columns to display:

head -n 10 filename.txt | cut -d ' ' -f 1,3

In this command, -d ' ' specifies the delimiter (space in this case), and -f 1,3 indicates that you want to display the first and third columns. Adjust the delimiter and field numbers as needed for your specific file format.

0 Comments

no data
Be the first to share your comment!