roy@sts.sts.UUCP (05/19/89)
I'm wondering if there's been a program written that takes a file and
outputs that same file except with arbitrary columns shifted over.
Some examples are:
input file is: 0123456789
Move column 7 to column 1: 0712345689
Move column 7 to column 1, column 3 to column 5: 0712453689
Move column 7 to column 1, column 3 to column 8: 0712456839
This sounds a bit like the bubble sort, so I think it probably exists.
Just out of curiosity, are there any other algorithms out there?
Thanks.
==================================================================
Roy Bixler                   | UUCP: ...!{claris,sun}!sts!roy    |
Semiconductor Test Solutions | Internet: sts!roy@Claris.COM      |
4101 Burton Dr.              | phones: (408) 727-2885 x132 (work)|
Santa Clara, CA  95054	     |         (408) 289-1035      (home)|
==================================================================roy@sts.sts.UUCP (05/20/89)
/* Written 12:04 pm  May 18, 1989 by roy@sts.sts.UUCP in sts:comp.sources.wanted */
/* ---------- "Column shifting" ---------- */
I'm wondering if there's been a program written that takes a file and
outputs that same file except with arbitrary columns shifted over.
Some examples are:
input file is: 0123456789
Move column 7 to column 1: 0712345689
Move column 7 to column 1, column 3 to column 5: 0712453689
Move column 7 to column 1, column 3 to column 8: 0712456839
This sounds a bit like the bubble sort, so I think it probably exists.
Just out of curiosity, are there any other algorithms out there?
Thanks.
/* End of text from sts:comp.sources.wanted */
Somebody just suggested using the "cut" command of SysV as the
solution to this.  I read the documentation and it looks like it
merely deletes certain columns or fields, but does not move them as I
wished.  Am I wrong about "cut"?  Any other ideas?
==================================================================
Roy Bixler                   | UUCP: ...!{claris,sun}!sts!roy    |
Semiconductor Test Solutions | Internet: sts!roy@Claris.COM      |
4101 Burton Dr.              | phones: (408) 727-2885 x132 (work)|
Santa Clara, CA  95054	     |         (408) 289-1035      (home)|
==================================================================bink@aplcen.apl.jhu.edu (Ubben Greg) (05/20/89)
In article <68200001@sts> roy@sts.sts.UUCP writes: > > I'm wondering if there's been a program written that takes a file and > outputs that same file except with arbitrary columns shifted over. Sed (the stream editor) does this very nicely: > Some examples are: > > input file is: 0123456789 > > Move column 7 to column 1: 0712345689 sed "s,\(.\)\(......\)\(.\),\1\3\2," > Move column 7 to column 1, column 3 to column 5: 0712453689 sed "s,\(.\)\(..\)\(.\)\(..\)\(.\)\(.\),\1\6\2\4\3\5," > Move column 7 to column 1, column 3 to column 8: 0712456839 sed "s,\(.\)\(..\)\(.\)\(...\)\(.\)\(.\),\1\5\2\4\6\3," This could be done using CUT and PASTE, but it is longer, messier, and slower: > Move column 7 to column 1, column 3 to column 5: 0712453689 tmp=/tmp/shift$$ trap "rm -f ${tmp}?; trap 0; exit" 0 1 2 15 cut -c1,8 $file >${tmp}a cut -c2-3,5-6 $file >${tmp}b cut -c4,7,9- $file | paste -d\\0 ${tmp}? - (3 more processes and 3 more files/pipes needed.) -- Greg Ubben bink@aplcen.apl.jhu.edu