[ale] swap 2 fields (in a tabbed file)?
John Wells
jb at sourceillustrated.com
Wed Jan 29 15:43:26 EST 2003
Chris,
An older version of sort, eh?
If it uses the -k, it probably won't accept the = sign...that's more of a
convention with -- than -.
Try sort -t ' ' -k 2.1 cblist.txt
With the whole ctrl+v, tab sequence again.
John
Christopher Bergeron said:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hmmm, no dice John:
>
> [root at tomahawk arrow]$ sort -t ' ' --key=2.1 cblist2.txt
> sort: unrecognized option `--'
> Try `sort --help' for more information.
>
> (and i did ctrl-V tab) in the quotes...
>
> And when i tried -k (instead of --key) i get:
> [root at tomahawk arrow]$ sort -k=2.1
> sort: invalid field specification `-k=2.1'
>
> The distro is RHAT 7.2.
> My man page for sort doesn't show --key as a valid value, but it does
> read this for -k:
>
> - -k POS1[,POS2]
> ~ start a key at POS1, end it *at* POS2 field numbers and
> character offsets are numbered
> ~ starting with one (contrast with zero-based +POS form)
>
>
> thanks for the help though...
>
>
>
>
> John Wells wrote:
>
> |sort -t ' ' --key=2.1 list.txt
> |
> |type "sort -t '", then hit ctrl+v, then press tab, the continue with "'
> |--key=2.1 list.txt".
> |
> |That works.
> |
> |John
> |
> |
> |
> |Christopher Bergeron said:
> |
> |>Ok, a sample of the data is attached. I need to sort by the
> alphabetical |> name of the second field I can do this easily using sort
> if I can swap |>the fields from:
> |>
> |>X\tY\n
> |>to:
> |>Y\tX\n
> |>
> |>Your awk script worked, but it considered the ^M as a field it looks
> |>like because it produced:
> |>Y\nX\t
> |>
> |>So i have a feeling we're very close. To the others that offered
> |>suggestions, I appreciate it. I'm partial to learning awk so for this
> |>run, i'm going to use it.
> |>
> |>
> |>Thanks,
> |>CB
> |>
> |>
> |>
> |>
> |>
> |>Geoffrey wrote:
> |>
> |>>Might you post one line of input to the list as an attachment? I (and
> |>>I think others) are having a hard time determining the actual format.
> |>>When you start dealing with funky (technical term) character combos,
> |>>like carriage return and newline, perl is likely to be the easiest
> |>>solution.
> |>>
> |>>
> |>>Christopher Bergeron wrote:
> |>>
> |>>>-----BEGIN PGP SIGNED MESSAGE-----
> |>>>Hash: SHA1
> |>>>
> |>>>Thanks Geoffrey! I think I've almost got it, but my output is
> |>>>appearing like this:
> |>>>
> |>>>GE CAPITAL CONSUMER LEND\n\tAFS74
> |>>>GEWARDS\n\tAFS75
> |>>>
> |>>>Instead of:
> |>>>GE CAPITAL CONSUMER LEND\tAFS74\n
> |>>>GEWARDS\tAFS75\n
> |>>>
> |>>>I have a feeling it's a simple change, but since I'm new to awk I'm
> a |>>>slow learner...
> |>>>
> |>>>Thanks again for any leads,
> |>>>- -CB
> |>>>
> |>>>
> |>>>Geoffrey wrote:
> |>>>
> |>>>| Use awk:
> |>>>|
> |>>>| awk -F '\t' '{printf "%s\t%s\n", $2, $1}'
> |>>>|
> |>>>| Christopher Bergeron wrote:
> |>>>|
> |>>>|> -----BEGIN PGP SIGNED MESSAGE-----
> |>>>|> Hash: SHA1
> |>>>|>
> |>>>|> Does anyone know how I can swap 2 fields in a tab delimited file
> |>>>|> containing 2 fields?
> |>>>|>
> |>>>|> Here's an example of my data:
> |>>>|> ~ <TAB>WOODSTOCK OUTLET<CR>
> |>>>|> AF100<TAB>METRO AUDIO DYNAMI<CR>
> |>>>|>
> |>>>|> What I'd like to do is swap the 2 fields (or do a `sort` based on
> |>>>the |> second field!) such that I end up with this:
> |>>>|> WOODSTOCK OUTLET<TAB> <CR>
> |>>>|> METRO AUDIO DYNAMICS<TAB>AF100<CR>
> |>>>|>
> |>>>|> Does anyone know of a way I can accomplish this? I tried using
> cut |>>>|> - -f2,1 -d"\t" but no adeu...
> |>>>|>
> |>>>|> As always, much thanks in advance!
> |>>>|> - -CB
> |>>>|> -----BEGIN PGP SIGNATURE-----
> |>>>|> Version: GnuPG v1.2.1 (MingW32)
> |>>>|> Comment: Using GnuPG with Netscape - http://enigmail.mozdev.org
> |> |>>>|>
> iD8DBQE+OBDCTKCy0t3zQgURAjNTAJ4+scGLwJ68zyWNCQi3zOioVQHYSgCgsbsd |>>>|>
> OQXrEikvL57cV8/Tj1vuqLg=
> |>>>|> =3GQm
> |>>>|> -----END PGP SIGNATURE-----
> |>>>|>
> |>>>|>
> |>>>|> _______________________________________________
> |>>>|> Ale mailing list
> |>>>|> Ale at ale.org
> |>>>|> http://www.ale.org/mailman/listinfo/ale
> |>>>|>
> |>>>|>
> |>>>|
> |>>>-----BEGIN PGP SIGNATURE-----
> |>>>Version: GnuPG v1.2.1 (MingW32)
> |>>>Comment: Using GnuPG with Netscape - http://enigmail.mozdev.org |>>>
> |>>>iD8DBQE+OBtfTKCy0t3zQgURAghVAKDGTNNK40g+4Jdl39eDsVPAeAgiZQCdF4Gg
> |>>>kncmOklKRZ00rGmPskLaj5Y=
> |>>>=577v
> |>>>-----END PGP SIGNATURE-----
> |>>>
> |>>>
> |>>>_______________________________________________
> |>>>Ale mailing list
> |>>>Ale at ale.org
> |>>>http://www.ale.org/mailman/listinfo/ale
> |>>
> |
> |
> |
> |
> |
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.1 (MingW32)
> Comment: Using GnuPG with Netscape - http://enigmail.mozdev.org
>
> iD8DBQE+ODkuTKCy0t3zQgURAmZtAJoCY+Vg43NvLTXDsTq1jbh4uDWdLACguviK
> Pi7LtrMDmX6FamrtLVipQ2Q=
> =5cHX
> -----END PGP SIGNATURE-----
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list