Glam Prestige Journal

Bright entertainment trends with youth appeal.

gawk -F\t works, but when it comes to sort, it fails. Under Linux or Cygwin, $'\t' will do it. However, to input a special key Tab, no way. Can anybody figure out a way?

3 Answers

In PowerShell, the escape character is `. A string containing a tab can be written as

"`t"

Thanks to fellows from Yahoo, Baidu and Stack Overflow, this tough problem is finally solved.

sort -t":" -k1 /var/log/accessfile

This statement give me a hint.

Now the answer is a combination of all tips.

  1. cmd /f:off
  2. sort -t" " -k16 foobar.txt 

    (the tab character is in double quotes)

foobar.txt is a text file with the tab separation.

The key is the double quotes ("").

A preferred option for me - rather than having to switch off tab-completion or change the mapped-key (to a different key) for it:-

Create a 'SetTabEV.cmd' script - to set an environment variable named "Tab" to be set to an environment variable (- consider keeping it accessible within/via your 'PATH') - you could always try the equivalent with a script for a *nix (Linux/UNIX) environment; e.g.:

Set Tab= 

Run it.

Then reference/pass it's value - '%Tab%'; e.g.:

MyScript.cmd "A%Tab%B%Tab%C"

Or for PowerShell:

PowerShell MyScript.ps1 """"A%Tab%B%Tab%C""""

But for PowerShell, one-less set of quotes is possibly preferred (- triple-quoting), by using/passing the PowerShell tab escape-sequence instead:

PowerShell MyScript.ps1 """A`tB`tC"""

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy