For Programmers: Free Programming Magazines  


Home > Archive > AWK > January 2006 > pipe as field separator









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 pipe as field separator
ramaka@foni.net

2005-11-28, 6:56 pm

Hello,

normal the field separator is a tabulator or ";". But my downlaod from
SAP has change in the sign "pipe".
---------------------------------------------------------
| InvBeleg |Pos|Material |Charge
---------------------------------------------------------
| 10051361 | 1|1201247 |
| 10051361 | 2|1202863 |
| 10051361 | 3|1204823 |

My idea was to change the field separator like this: FS =3D "|", but it
doesn't work.

An other idea was to replace the pipe on this way: gsub ( "|" , ";" ,
=A70), but it also doesn't work.

What ist wrong? Can someone help me? That in advance.

Randolf

Kenny McCormack

2005-11-28, 6:56 pm

In article <1133186711.074989.106350@g44g2000cwa.googlegroups.com>,
<ramaka@foni.net> wrote:
....
>My idea was to change the field separator like this: FS =3D "|", but it
>doesn't work.
>
>An other idea was to replace the pipe on this way: gsub ( "|" , ";" ,
>=A70), but it also doesn't work.
>
>What ist wrong? Can someone help me? That in advance.


You'll need to define "not work".

Chris F.A. Johnson

2005-11-28, 6:56 pm

On 2005-11-28, ramaka@foni.net wrote:
> Hello,
>
> normal the field separator is a tabulator or ";". But my downlaod from
> SAP has change in the sign "pipe".
> ---------------------------------------------------------
>| InvBeleg |Pos|Material |Charge
> ---------------------------------------------------------
>| 10051361 | 1|1201247 |
>| 10051361 | 2|1202863 |
>| 10051361 | 3|1204823 |
>
> My idea was to change the field separator like this: FS = "|", but it
> doesn't work.
>
> An other idea was to replace the pipe on this way: gsub ( "|" , ";" ,
> §0), but it also doesn't work.


What does "doesn't work" mean? What *does* it do? What do you want
it to do? Where is your code that isn't working?

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
Ed Morton

2005-11-28, 6:56 pm

ramaka@foni.net wrote:
> Hello,
>
> normal the field separator is a tabulator or ";". But my downlaod from
> SAP has change in the sign "pipe".
> ---------------------------------------------------------
> | InvBeleg |Pos|Material |Charge
> ---------------------------------------------------------
> | 10051361 | 1|1201247 |
> | 10051361 | 2|1202863 |
> | 10051361 | 3|1204823 |
>
> My idea was to change the field separator like this: FS = "|", but it
> doesn't work.
>
> An other idea was to replace the pipe on this way: gsub ( "|" , ";" ,
> §0), but it also doesn't work.
>
> What ist wrong? Can someone help me? That in advance.
>
> Randolf
>


Try this:

awk 'BGIN{FS="|";OFS=";'}$1=$1' file

If that doesn't change the |s to ;s, there's something wrong with your
file and/or OS.

Ed.
Ed Morton

2005-11-28, 6:56 pm

Ed Morton wrote:

> awk 'BGIN{FS="|";OFS=";'}$1=$1' file


Make that:

awk 'BGIN{FS="|";OFS=";"}$1=$1' file
news.t-online.de

2005-11-28, 6:56 pm

ramaka@foni.net wrote:
> Hello,
>
> normal the field separator is a tabulator or ";". But my downlaod from
> SAP has change in the sign "pipe".
> ---------------------------------------------------------
> | InvBeleg |Pos|Material |Charge
> ---------------------------------------------------------
> | 10051361 | 1|1201247 |
> | 10051361 | 2|1202863 |
> | 10051361 | 3|1204823 |
>
> My idea was to change the field separator like this: FS = "|", but it
> doesn't work.
>
> An other idea was to replace the pipe on this way: gsub ( "|" , ";" ,
> §0), but it also doesn't work.
>
> What ist wrong? Can someone help me? That in advance.
>
> Randolf


>

This FS also removes traling and leading Blanks
from the fields.

Warning:
If you bring and show your awk abilities
to your SAP collegues, then they might be
disgusted because they feel inferior
to you, like these root picking a micronesian island
tribes would feel, when a jet pilot shows them his Boing 747
after an emergency landing, next to their
n-tree-flowed.


BEGIN{
FS="[ ]*[|][ ]*"
}
NR>3{ #we don not want to see the 4 line header
print $1
print "InvBeleg: " $2
print "Pos: " $3
print "Material: " $4
print "Charge: " $5
}


InvBeleg: 10051361
Pos: 1
Material: 1201247
Charge:

InvBeleg: 10051361
Pos: 2
Material: 1202863
Charge:

InvBeleg: 10051361
Pos: 3
Material: 1204823
Charge:
William James

2005-11-28, 6:56 pm

news.t-online.de wrote:
> ramaka@foni.net wrote:
>
> This FS also removes traling and leading Blanks
> from the fields.
>
> Warning:
> If you bring and show your awk abilities
> to your SAP collegues, then they might be
> disgusted because they feel inferior
> to you, like these root picking a micronesian island
> tribes would feel, when a jet pilot shows them his Boing 747
> after an emergency landing, next to their
> n-tree-flowed.
>
>
> BEGIN{
> FS=3D"[ ]*[|][ ]*"


Why not make it remove tabs as well as blanks?

FS=3D"[ \t]*[|][ \t]*"

> }
> NR>3{ #we don not want to see the 4 line header
> print $1
> print "InvBeleg: " $2
> print "Pos: " $3
> print "Material: " $4
> print "Charge: " $5
> }
>
>
> InvBeleg: 10051361
> Pos: 1
> Material: 1201247
> Charge:
>
> InvBeleg: 10051361
> Pos: 2
> Material: 1202863
> Charge:
>=20
> InvBeleg: 10051361
> Pos: 3
> Material: 1204823
> Charge:


Loki Harfagr

2005-11-29, 7:55 am

Le Mon, 28 Nov 2005 08:42:01 -0600, Ed Morton a écrit_:

> Ed Morton wrote:
>
>
> Make that:
>
> awk 'BGIN{FS="|";OFS=";"}$1=$1' file


s/BGIN/BEGIN/
E. Rosten

2005-11-29, 6:56 pm

On Tue, 29 Nov 2005 13:21:04 +0100, Loki Harfagr wrote:

> Le Mon, 28 Nov 2005 08:42:01 -0600, Ed Morton a écrit_:
>
>
> s/BGIN/BEGIN/


Er, this is an awk group.

sub(/BGIN/,"BEGIN")

-Ed


--
(You can't go wrong with psycho-rats.) (er258)(@)(eng.cam)(.ac.uk)

/d{def}def/f{/Times findfont s scalefont setfont}d/s{10}d/r{roll}d f 5/m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}
for /s 15 d f pop 240 420 m 0 1 3 { 4 2 1 r sub -1 r show } for showpage

MArek Simon

2006-01-10, 3:58 am

ramaka@foni.net wrote:
> Hello,
>
> normal the field separator is a tabulator or ";". But my downlaod from
> SAP has change in the sign "pipe".


I think there is other way to solve it. Can you change some settings of
SAP to gain CSV again?
MArek
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com