HowTo? : convert file, take two line parts 
Author Message
 HowTo? : convert file, take two line parts

Since I'm not an experienced awk user, nor unix user I would like to
ask this simple question.

I have to adjust an old script which fetches a file from one machine
to another. I have to make a little conversion before sending the file
to the next program.

I guess that awk can do this simple task for me, if I only knew how !

The input file looks something like this:
01219111001999900202016PK111a1"3.50"MSDOS 11BRANS G.B.P.W.
01219111001999900202036PK111a1"3.50"MSDOS WESTELAARSTRAAT 30

It has to be converted into this
99900202016BRANS G.B.P.W.
99900202036WESTELAARSTRAAT 30

So take 11 characters from position 13 and 70 characters from position
45.

I created a convert.awk file which looks like this :
substr($1,13,11)+substr($1,45,70)

I run it like this :
awk -f convert.awk originalfile > convertedfile

But this only generates this :
01219111001999900202016PK
01219111001999900202036PK

What am I doing wrong and how should it be done ?

Thanks in advance for any help,
Peter


[see also my private address at http://www.*-*-*.com/ ~pfranken]



Tue, 29 May 2001 03:00:00 GMT  
 HowTo? : convert file, take two line parts
After some browsinging though this newgroup I found :

cut -c1-12,23-44 originalfile >convertedfile

But even this gives back the same result ????, What am I missing.

Peter

[see also my private address at http://home.westbrabant.net/~pfranken]



Tue, 29 May 2001 03:00:00 GMT  
 HowTo? : convert file, take two line parts
Still more, I noticed that the input file contains some raw ascii

not understanding this.

Is there another method ?

Peter

[see also my private address at http://home.westbrabant.net/~pfranken]



Tue, 29 May 2001 03:00:00 GMT  
 HowTo? : convert file, take two line parts

Quote:

> Since I'm not an experienced awk user, nor unix user I would like to
> ask this simple question.

> I have to adjust an old script which fetches a file from one machine
> to another. I have to make a little conversion before sending the file
> to the next program.

> I guess that awk can do this simple task for me, if I only knew how !

> The input file looks something like this:
> 01219111001999900202016PK111a1"3.50"MSDOS 11BRANS G.B.P.W.
> 01219111001999900202036PK111a1"3.50"MSDOS WESTELAARSTRAAT 30

> It has to be converted into this
> 99900202016BRANS G.B.P.W.
> 99900202036WESTELAARSTRAAT 30

> So take 11 characters from position 13 and 70 characters from position
> 45.

> I created a convert.awk file which looks like this :
> substr($1,13,11)+substr($1,45,70)

> I run it like this :
> awk -f convert.awk originalfile > convertedfile

> But this only generates this :
> 01219111001999900202016PK
> 01219111001999900202036PK

> What am I doing wrong and how should it be done ?

> Thanks in advance for any help,
> Peter


> [see also my private address at http://home.westbrabant.net/~pfranken]



01219111001999900202016PK111a1"3.50"MSDOS 1BRANS G.B.P.W.
01219111001999900202036PK111a1"3.50"MSDOS 1WESTELAARSTRAAT 30



99900202016BRANS G.B.P.W.
99900202036WESTELAARSTRAAT 30

--
Maurizio Loreti                      http://wwwcdf.pd.infn.it/~loreti/mlo.html



Tue, 29 May 2001 03:00:00 GMT  
 HowTo? : convert file, take two line parts

Quote:

>Since I'm not an experienced awk user, nor unix user I would like to
>ask this simple question.

>I have to adjust an old script which fetches a file from one machine
>to another. I have to make a little conversion before sending the file
>to the next program.

>I guess that awk can do this simple task for me, if I only knew how !

>The input file looks something like this:
>01219111001999900202016PK111a1"3.50"MSDOS 11BRANS G.B.P.W.
>01219111001999900202036PK111a1"3.50"MSDOS WESTELAARSTRAAT 30

>It has to be converted into this
>99900202016BRANS G.B.P.W.
>99900202036WESTELAARSTRAAT 30

>So take 11 characters from position 13 and 70 characters from position
>45.

>I created a convert.awk file which looks like this :
>substr($1,13,11)+substr($1,45,70)

>I run it like this :
>awk -f convert.awk originalfile > convertedfile

>But this only generates this :
>01219111001999900202016PK
>01219111001999900202036PK

>What am I doing wrong and how should it be done ?

Here's what I'd use for convert.awk to take those character ranges:

{print substr($0,13,11) substr($0,45,70)}

On your data, it produces:

99900202016BRANS G.B.P.W.
99900202036STELAARSTRAAT 30

Note that the second line isn't what you wanted (according to what
you showed as output), but it is the patched together output of the
two substring sections.  Check where column 45 is on line 2.

Note also that I used $0, not $1, to get the whole line.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 29 May 2001 03:00:00 GMT  
 HowTo? : convert file, take two line parts

Quote:

> The input file looks something like this:
> 01219111001999900202016PK111a1"3.50"MSDOS 11BRANS G.B.P.W.
> 01219111001999900202036PK111a1"3.50"MSDOS WESTELAARSTRAAT 30

> It has to be converted into this
> 99900202016BRANS G.B.P.W.
> 99900202036WESTELAARSTRAAT 30

> So take 11 characters from position 13 and 70 characters from position
> 45.

 My first choice to do this would be sed:
sed 's/^.\{10\}\(.\{13\}\).\{21\}\(.*\)$/\1\2/'  inputFile >outputFile
substitute==s
from line-start ^ to line-end $
the string as follows
(I) 10 arbitrary characters .\{10\}
(II) marked-tagged  by \( \) 13 characters
(III) 21 characters
(IV) tagged:  all characters in the rest of the line \(.*\)
by (II)=first-tagged=\1 and (IV)=second-tagged=\2
Alternative: (workes only on lines longer than 113 chars)
sed 's/^.\{10\}\(.\{13\}\).\{21\}\(.\{70\}\)/\1\2/'  inputFile

Quote:
>outputFile

The same with awk:
awk '{ firstChunk=substr($0,11,13)
             secondChunk=substr($0,45)
             print firstChunk secondCunk
Quote:
}'  inputFile >outputFile

or shorter:
awk '{  print substr($0,11,13) substr($0,45) }'  inputFile >outputFile

 partly tested
 LMS

free sed/awk book:
      ftp://ftp.u-aizu.ac.jp/u-aizu/doc/Tech-Report/1997/97-2-007.ps.gz
      ftp://ftp.u-aizu.ac.jp/u-aizu/doc/Tech-Report/1997/97-2-007.tar.gz



Wed, 30 May 2001 03:00:00 GMT  
 HowTo? : convert file, take two line parts
Wow, thanks to all. Great newsgroup, I got plenty of decent responses
from you all. I'm used to some other grous which mostly generate at no
or only one response.

The solution I now have is :


Quote:
>outputfile

It clears out all the unwanted characters and takes the two correct
parts.

Peter


[see also my private address at http://home.westbrabant.net/~pfranken]



Fri, 01 Jun 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. How to compare two files line-by-line

2. read two sets of data from two spread sheet files to two arrays problem

3. Writing two equal files without creating two files in dct

4. Need to split file with two reports per line

5. Ranges in AWK (file name is two lines down)

6. Two lines to one line

7. BLT: How to fill under a line or between two lines

8. SGI: Breaking a format line into two lines

9. Taking the integer part of a float.

10. takes a dword from eax and converts it in it's hexadecimal representation - ex

11. Newbie Import two coloums of floating point data into python HOWTO

12. EQU expressions taking up more lines

 

 
Powered by phpBB® Forum Software