I have a text file, I only want the first column and the last column. However the problem is they are separated by both whitespace and tabs at random places, making it hard for me to use cut
USER02163 name BAD
USER5415 ab lsi ei GOOD
USER15356 sl oe ow BAD
Desired output is:
USER02163 BAD
USER5415 GOOD
USER15356 BAD
Does anyone have a hacky way I can get my desired output?
ALT + Left Mouse Click puts you in Column Mode Select. It's quite an useful shortcut that may help you. This is by far the simplest solution. Copy the file, edit the copy, cut out the non-needed columns.
awk to print the first column. The first column of any file can be printed by using $1 variable in awk. But if the value of the first column contains multiple words then only the first word of the first column prints. By using a specific delimiter, the first column can be printed properly.
Easiest by using awk
. The command is:
awk '{print $1, $NF}' filename
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With