wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes AWK tutorial how to delimiter a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "AWK tutorial how to delimiter a file" Watch "AWK tutorial how to delimiter a file" New topic
Author

AWK tutorial how to delimiter a file

Peter Rooke
Ranch Hand

Joined: Oct 21, 2004
Posts: 805

Could someone (please) post a good tutorial or advice for (n)awk. I'm trying to get this data:

Denmark DKAAB DK0001 Aabenraa
U.A.E. AE0002 Abu Dhabi

to look like this:
Denmark, DKAAB, DK0001, Aabenraa
U.A.E., ,AE0002, Abu Dhabi

I can match all of one of the columns with: [A-Z][A-Z][0-9][0-9][0-9][0-9] eg ('DK0001')
and another column with: [A-Z][A-Z][A-Z][A-Z][A-Z]

Been reading awk web pages for the last two hours too complex.


Regards Pete
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
I think sed would be a better tool. The following script works for your data sample


Caireann:~ gerardo$ sed -E "s/\ {0,1}([A-Z]{5}){0,1}\ ([A-Z]{2}[0-9]{4})/,\\1,\\2,/g" testdata.txt

Gives the following output

Denmark,DKAAB,DK0001, Aabenraa
U.A.E.,,AE0002, Abu Dhabi
Peter Rooke
Ranch Hand

Joined: Oct 21, 2004
Posts: 805

Many thanks....
Rocky Salve
Greenhorn

Joined: Apr 05, 2006
Posts: 16
Hi

i need a resource on the net to find a good tutorial
on using awk and sed programming

anyaone gotta it!!!

plz help
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42944
    
  68
The Grymoire has awk and sed tutorials.
Rocky Salve
Greenhorn

Joined: Apr 05, 2006
Posts: 16
thanks a lot !
it proved to be a hit!!!
Rocky Salve
Greenhorn

Joined: Apr 05, 2006
Posts: 16
Now can anyone help give resources to succeed the RHCE exam

plz
Rocky Salve
Greenhorn

Joined: Apr 05, 2006
Posts: 16
thks ulf pal

it proved useful

now i can fire rockets
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AWK tutorial how to delimiter a file