Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Omitting fields 1

Status
Not open for further replies.

paulchen

Technical User
Nov 30, 2006
2
DE
Hi all,
it seems to be an easy problem, but I can't solve it.
I do have records with a certain field containing a single "M". Mostly the "M" is located at third position which is OK. But there are other records in that the "M"-field is located at fourth, fifths or later position. Those records needs to be changed. In other words: I need to write from two fields before the "M" until the end of line.
Example:
4076 4942 M (38,19 \200 )
; 2956 4934 M (Gesamtsumme:)
269 362 M (Dr. med. Jochen Sxxxr)
: 3118 241 1306 151 rc 3118 362 M (Facharzt f\374r Urologie)
269 518 M (Erwin-Vornberger-Platz 1)
269 630 M (47807 Krefeld)
3174 526 M (Tel.: 0xxx1/97694 Fax: 0xxx1/97695)
: 3336 547 1082 91 rc 3336 620 M (E-Mail: dr@xxxfers.de)

and it should look like:
4076 4942 M (38,19 \200 )
2956 4934 M (Gesamtsumme:)
269 362 M (Dr. med. Jochen Sxxxs)
3118 362 M (Facharzt f\374r Urologie)
269 518 M (Erwin-Vornberger-Platz 1)
269 630 M (97209 Veitsh\366chheim)
3174 526 M (Tel.: 0xxx/97694 Fax: 0xxx/97695)
3336 620 M (E-Mail: dr@xxxers.de)

Thanks a lot,
paulchen
 
A starting point (endless loop risk ...):
awk '{while($3!="M"){$1="";$0=$0};print}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PH,

thanks a lot - it did it. There is still a leading blank but it's OK. Could you tell me what the $0=$0 means? Does it refresh the entire line?

Thanks,
Paul.
 
what the $0=$0 means
Parse the input line again and thus recalculate the fields.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
There is still a leading blank
awk '{while($3!="M"){$1="";sub(/ +/,"")};print}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top