Вы можете использовать GNU datamash
(новая программа командной строки), которая имеет встроенную команду transpose
со строгой проверкой ввода.
Пример:
$ cat in.txt
Column1 Column2 Column3
Row1_Col1 Row1_Col2 Row1_Col3
Row2_Col1 Row2_Col2 Row2_Col3
Row3_Col1 Row3_Col2 Row3_Col3
$ datamash transpose < in.txt
Column1 Row1_Col1 Row2_Col1 Row3_Col1
Column2 Row1_Col2 Row2_Col2 Row3_Col2
Column3 Row1_Col3 Row2_Col3 Row3_Col3
Затем разделите по столбцам с помощью cut
:
$ datamash transpose < in.txt | cut -f1,3 | tr '\t' '='
Column1=Row2_Col1
Column2=Row2_Col2
Column3=Row2_Col3
Для создания нескольких файлов можно использовать следующее:
for i in 2 3 4 ; do
datamash transpose < in.txt | cut -f1,$i | tr '\t' '=' > file$i.txt
done
GNU Datamash доступен здесь: http://www.gnu.org/s/datamash ,
и пакеты доступны в нескольких дистрибутивах gnu/linux
(отказ от ответственности: я являюсь разработчиком
Датамаша
).
Псевдонимы так не работают, но вместо них можно использовать переменную:
somedir="/var/www/site"
cd "$somedir/app"
С должным уважением Fox и RoVo за предложение этого в комментариях
И если вы хотите сэкономить несколько нажатий клавиш, вы можете настроить псевдоним:
alias somedir='cd "$somedir"'
Или, если вы включите autocd
, вы можете cd
, просто указав переменную как команду:
~$ shopt -s autocd
~$ "$somedir"
/var/www/site$
Цитирование удобной ссылки на Bash(выделение мое):
A Bash alias is essentially nothing more than a keyboard shortcut, an abbreviation, a means of avoiding typing a long command sequence.... It would be nice if aliases could assume some of the functionality of the C preprocessor, such as macro expansion, but unfortunately Bash does not expand arguments within the alias body. Moreover, a script fails to expand an alias itself within "compound constructs," such as if/then statements, loops, and functions. An added limitation is that an alias will not expand recursively. Almost invariably, whatever we would like an alias to do could be accomplished much more effectively with a function.
Несмотря на ваш частный случай CDPATH
, , как ответил Кусалананда , эквивалентная функция может выглядеть как:
somedir() {
cd /var/www/site/"${1:-}"
}
Теперь у вас есть:
$ pwd
/tmp
$ somedir
$ pwd
/var/www/site
$ somedir app
$ pwd
/var/www/site/app