[ale] swap 2 fields (in a tabbed file)?

Jason Day jasonday at worldnet.att.net
Wed Jan 29 14:23:13 EST 2003


On Wed, Jan 29, 2003 at 12:34:59PM -0500, Christopher Bergeron wrote:
> 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...

perl -p -i -e 's/^(.*)\t(.*)$/$2\t$1/' filename

This will overwrite the original file, so either work on a copy, or give
an argument to the -i option (perl -p -i.orig -e ...).

Jason
-- 
Jason Day                                       jasonday at
http://jasonday.home.att.net                    worldnet dot att dot net
 
"Of course I'm paranoid, everyone is trying to kill me."
    -- Weyoun-6, Star Trek: Deep Space 9
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list