Город МОСКОВСКИЙ
00:02:26

Unix & Linux: How to define 'tab' delimiter with 'cut' in BASH? (4 Solutions!!)

Аватар
Курсы самореализации
Просмотры:
19
Дата загрузки:
11.10.2024 07:34
Длительность:
00:02:26
Категория:
Обучение

Описание

Unix & Linux: How to define 'tab' delimiter with 'cut' in BASH?


The Question: Here is an example of using cut to break input into fields using a space
delimiter, and obtaining the second field:
cut -f2 -d' '
How can the delimiter be defined as a tab, instead of a space?

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

== This solution helped 345 people ==
Two ways:
Press Ctrl+V and then Tab.
cut -f2 -d' ' infile
or write it like this:
cut -f2 -d$'t' infile

== This solution helped 14 people ==
awk -F 't' '{ print $2 }' inputfile
This extracts the second tab-delimited field of each line of input from
inputfile.

== This solution helped 211 people ==
Tab is the default.
See the http://www.manpagez.com/man/1/cut/.
-d delim
Use delim as the field delimiter character instead of the tab
character.
So you should just write
cut -f 2

With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user nobar (https://unix.stackexchange.com/users/6764), user Muhammad Hasan Khan (https://unix.stackexchange.com/users/17204), user Mikel (https://unix.stackexchange.com/users/3169), user Kusalananda (https://unix.stackexchange.com/users/116858), user Ilja (https://unix.stackexchange.com/users/16961), user G-Man Says 'Reinstate Monica' (https://unix.stackexchange.com/users/80216), user Birei (https://unix.stackexchange.com/users/8685), user Alex Willison (https://unix.stackexchange.com/users/204540), and the Stack Exchange Network (http://unix.stackexchange.com/questions/35369). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.

Рекомендуемые видео