File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AWK tutorial how to delimiter a file

 
Peter Rooke
Ranch Hand
Posts: 825
Java Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
Java Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks....
 
Rocky Salve
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Grymoire has awk and sed tutorials.
 
Rocky Salve
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot !
it proved to be a hit!!!
 
Rocky Salve
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now can anyone help give resources to succeed the RHCE exam

plz
 
Rocky Salve
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thks ulf pal

it proved useful

now i can fire rockets
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic