awk is a very useful and powerful command in Unix. It's used to work with columns in a text file.
Here is a simple awk command to list the data of 1st column in a text file.
awk '{print $1}' file_name
We can specify the field-separator using -F option. Refer below example.
Here tab is the filed separator. Below command will print the content of Column 2 in text file.
awk -F'\t' '{print $2}' file_name
We can print the length of data in column 2 using below awk command.
awk -F'\t' '{print length($2)}' file_name
We can check conditions in awk command and print accordingly.
awk -F'\t' '{if(length($4) > 50 ) print $4} ' file_name
The above command will print all the data in Column 4 if length of data is greater than 50 characters.
For more Tips & Tricks in Unix, Click Here.
Here is a simple awk command to list the data of 1st column in a text file.
awk '{print $1}' file_name
We can specify the field-separator using -F option. Refer below example.
Here tab is the filed separator. Below command will print the content of Column 2 in text file.
awk -F'\t' '{print $2}' file_name
We can print the length of data in column 2 using below awk command.
awk -F'\t' '{print length($2)}' file_name
We can check conditions in awk command and print accordingly.
awk -F'\t' '{if(length($4) > 50 ) print $4} ' file_name
The above command will print all the data in Column 4 if length of data is greater than 50 characters.
No comments:
Post a Comment
Please give your feedback, questions and suggestions. I will surely answer you.