One of the most viewed posts on this blog is the unix-join-with-tabs one where I describe the "Ctrl-v
cut -f':' --output-delimiter=<tab>
where the output delimiter needs to be a tab.
However, there's a much nicer/easier way of specifying a tab character in bash:
$'\t'
. Take a look a the QUOTING section of the bash manpage for all the details.
Here's a simple example of it in action:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo -e "second:first" |\ | |
cut -d: --output-delimiter=$'\t' -f 1,2 |\ | |
awk -F $'\t' 'BEGIN{OFS=FS}{print $2,$1}' | |
# outputs: "first<tab>second" |
No comments:
Post a Comment