Cut command to specify the tab as the delimiter [closed] Cut command to specify the tab as the delimiter [closed] shell shell

Cut command to specify the tab as the delimiter [closed]


Cut splits the input lines at the given delimiter (-d, --delimiter).

To split by tabs omit the -d option, because splitting by tabs is the default.

By using the -f (--fields) option you can specify the fields you are interrested in.

echo -e "a\tb\tc" |cut -f 1 # outputs "a"echo -e "a\tb\tc" |cut -f 2 # outputs "b"echo -e "a\tb\tc" |cut -f 3 # outputs "c"echo -e "a\tb\tc" |cut -f 1,3 # outputs "a\tc"echo -e "a\tb\tc\td\te" |cut -f 2-4 # outputs "b\tc\td"

You can also specify the output delimiter (--output-delimiter) and get rid of lines not containing any delimiters (-s/--only-delimited)

echo -e "a\tb\tc\td\te" |cut -f 2-4 --output-delimiter=":" # outputs b:c:d

If you are interrested in the first field of your input file simply do...

cut -f 1 file.txt


Default delimiter is '\t' so you just need to execute:

cut -f <n> file.txt

Where <n> is the number of the column


You can try to place a tab between the quotes if you first press " v" then the "" key

eg  cat > test.txt a    b     c<ctrl d>$ grep test.txt | cut -f 2 -d "<ctrl v> <presstab>"

will return "b"