The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 03-16-2008
yunccll yunccll is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 23
FS means Field Separator , using FS="( )|(,)" means current FS is the space or ','
if you use the statement, the result is
lastname1 111 Hilversum
lastname2 222 Bussum
lastname3 333 Amsterdam

without FS="()|(,)" result is :
lastname1 111, Hilversum
lastname2 222, Bussum
lastname3 333, Amsterdam

they are different, first is 111 and the next is 111,

Code:
> cat data
Person:
Name: Firstname1 lastname1
Address: 111, Street "Narder straat"
City : Hilversum
 
Person:
Name : Fistname2 lastname2
Address: 222, Street "Zoud straat"
City: Bussum
 
Person:
Name : Firstname2 lastname3
Address: 333, Street "Station straat"
City: Amsterdam
Code:
> awk 'BEGIN{FS="( )|(,)"} /^Name/{n=$NF}/^Address/{a=$2" "$4" "$5}/^City/{print n,a,$NF}' data
lastname1 111 "Narder straat" Hilversum
lastname2 222 "Zoud straat" Bussum
lastname3 333 "Station straat" Amsterdam
.Aaron