1

Hello I would like to perform an alias to get an specific colum, parameter using a separator in order to achieve this i decided to use the cut command I created the alias as follows, and I saved it in the corresponding bashrc file:

alias getColumn='cat $1 | cut -d'$2' -f'$3''

However when I tested it I got:

VirtualBox:~$ getColumn /tmp/tmp.9Eusfk5cKZ , 3
cut: the delimiter must be a single character
Try 'cut --help' for more information.

SeVirtualBox:~$ getColumn /tmp/tmp.9Eusfk5cKZ "," "3"
cut: the delimiter must be a single character
Try 'cut --help' for more information.
cond try:

After feedback from here I tried:

#function to get a column
function getColumn() {
    cut -d"$2" -f"$3" "$1"
}

However I got:

VirtualBox:~$ getColumn topics " " 2
cut: the delimiter must be a single character
Try 'cut --help' for more information.

I am using ubuntu for this proves,

neo33
  • 131

1 Answers1

3

From the bash man page:

There is no mechanism for using arguments in the replacement text. If arguments are needed, a shell function should be used.

Try something like this in your .bashrc instead:

getColumn() {
    cut -d"$2" -f"$3" "$1"
}
wjandrea
  • 14,236
  • 4
  • 48
  • 98
user4556274
  • 4,877