![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Report generation | gmahesh2k | Shell Programming and Scripting | 3 | 05-16-2008 03:33 AM |
| report generation | gmahesh2k | UNIX for Dummies Questions & Answers | 2 | 05-16-2008 02:41 AM |
| Generation file copying for tech support backup | sjohnson | UNIX for Dummies Questions & Answers | 12 | 04-04-2008 08:39 AM |
| Oracle Report generation | DILEEP410 | Shell Programming and Scripting | 7 | 01-04-2007 04:52 AM |
| Bar code generation in to the text file and printing the same using lp command. | Manjunath Naik | SUN Solaris | 0 | 05-26-2005 03:50 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
awk- report generation from input file
I have input file with below content:
Person: Name: Firstname1 lastname1 Address: 111, Straat City : Hilversum Person: Name : Fistname2 lastname2 Address: 222, street Cit: Bussum Person: Name : Firstname2 lastname3 Address: 333, station straat City: Amsterdam I need the output file withe the below contents: lastname1 111 Hilversum lastname2 222 Bussum lastname3 333 Amsterdam is it possible, if yes how? Thanks |
|
||||
|
awk- report generation from input file
Thanks Klashxx
its Wonderful, it works. I was trying to undersand what does FS="( )|(,)" do? Could you please give more info on this, however without the above also the output is same awk '/^Name/{n=$NF}/^Address/{a=$2}/^City/{print n,a,$NF}' inpfile lastname1 111, Hilversum lastname2 222, Bussum lastname3 333, Amsterdam now the request is different: the input file is : 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 I need the outout file as below: lastname1 111 "Narder straat" Hilversum lastname2 222 "Zoud straat" Bussum lastname3 333 "Station straat" Amsterdam Thanks again |
|
||||
|
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 |
|
||||
|
Hi Aaron,
This is fine, so we are displaying 4 and 5 th fields of Address. I am not sure if the street contains only 2 fields , it can contain more fields like “your and my straat & others straat as well”, in this case I can’t use just 4 th and 5 th fileds. So to be very clear, my requirement is I need a 3 rd field from the line that contains Name with FS “ “ space: I need 2 nd field from the line that contains Address with FS ( ) space and need 2 nd filed from the same line with FS ( “ ) Quote and I need 2 nd field form the line that contains City with FS ( ) space. Thanks again. McLan |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|