Unix questions - UNIX - to join files

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > October 2005 > UNIX - to join files





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author UNIX - to join files
zhezell@hotmail.com

2005-10-05, 9:04 pm

I have just started learning UNIX & I have encountered a problem when
trying to rearrange my fields. When I use AWK or CUT to add a field to
the last column of my file, the field does not join to the end of the
last column but overlaps the first column. When I add a field to the
beginning of my file it works well. Is there a way I can make my new
field attach to my last column ?

Ed Morton

2005-10-06, 2:49 am

zhezell@hotmail.com wrote:
> I have just started learning UNIX & I have encountered a problem when
> trying to rearrange my fields. When I use AWK or CUT to add a field to
> the last column of my file, the field does not join to the end of the
> last column but overlaps the first column. When I add a field to the
> beginning of my file it works well. Is there a way I can make my new
> field attach to my last column ?
>


Sounds like you might want "paste". If not, post some sample input and
output to clarify.

Ed.
jpd

2005-10-06, 2:49 am

Begin <1128560227.860446.326390@g47g2000cwa.googlegroups.com>
On 2005-10-06, zhezell@hotmail.com <zhezell@hotmail.com> wrote:
> I have just started learning UNIX & I have encountered a problem when
> trying to rearrange my fields. When I use AWK or CUT to add a field to
> the last column of my file, the field does not join to the end of the
> last column but overlaps the first column. When I add a field to the
> beginning of my file it works well. Is there a way I can make my new
> field attach to my last column ?


Might be a trailing \r problem in your data. This will make it *look*
like the appended data overwrites the start of the line. Else, show
code, and sample data.


--
j p d (at) d s b (dot) t u d e l f t (dot) n l .
Bill Marcum

2005-10-06, 2:49 am

On 5 Oct 2005 17:57:07 -0700, zhezell@hotmail.com
<zhezell@hotmail.com> wrote:
> I have just started learning UNIX & I have encountered a problem when
> trying to rearrange my fields. When I use AWK or CUT to add a field to
> the last column of my file, the field does not join to the end of the
> last column but overlaps the first column. When I add a field to the
> beginning of my file it works well. Is there a way I can make my new
> field attach to my last column ?
>

The reason the field seems to overlap the first column is this: In
Windows, every line of a text file ends with two characters called CR
and LF. In Unix, every line ends with LF. If you copy a Windows file
to Unix without converting it, then add characters to the end of a line,
those characters are added between the CR and LF. The CR (carriage
return) causes the cursor to move to the start of the line.
There are various ways to deal with end-of-line characters. In awk, you
can use sub(/\015/,"",$0) or sub(/\015/,"new text\015",$0)
Other ways include tr, dos2unix, or ftp in ascii mode.


--
There must be more to life than having everything.
-- Maurice Sendak
Floyd L. Davidson

2005-10-06, 2:49 am

Bill Marcum <bmarcum@iglou.com> wrote:
>On 5 Oct 2005 17:57:07 -0700, zhezell@hotmail.com
> <zhezell@hotmail.com> wrote:
>The reason the field seems to overlap the first column is this: In
>Windows, every line of a text file ends with two characters called CR
>and LF. In Unix, every line ends with LF. If you copy a Windows file
>to Unix without converting it, then add characters to the end of a line,
>those characters are added between the CR and LF. The CR (carriage
>return) causes the cursor to move to the start of the line.
>There are various ways to deal with end-of-line characters. In awk, you
>can use sub(/\015/,"",$0) or sub(/\015/,"new text\015",$0)
>Other ways include tr, dos2unix, or ftp in ascii mode.


Or use the original UNIX utility specifically intended to handle that!

col -xb < infile > outfile

--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@apaflo.com
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com