AllExperts > Experts 
Search      

Unix/Linux OS

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Unix/Linux OS Answers
Question Library

Ask a question about Unix/Linux OS
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About nix
Expertise
UNIX, programing, C, C++, awk, shell scripts, Web, HTTP, Apache, firewall, AltaVista firewall, E-Mail, sendmail, IMAP4 POP3, DNS, NTP, system administration, TCP/IP, security

Experience
UNIX
Digital UNIX
AltaVista Firewall
TCP/IP

Education/Credentials
BSCS

 
   

You are here:  Experts > Computing/Technology > Focus on Unix > Unix/Linux OS > awk command

Topic: Unix/Linux OS



Expert: nix
Date: 9/23/2008
Subject: awk command

Question
Nix, that worked!! Thanks. I just have a question on how it did work. Here's the command you gave me:
awk -F '","' '{split($4, a, ","); print $2, a[2]}'

Here's a real row from my data:
"KINGS EAGLE, INC.","ATP9750106","123456789","1234567890",$189.93,"C"

I needed the 2nd and the 5th field put on a new file. I ran your code and it worked. But in the code you gave me, where did you specify the 5th field?

Answer
:-)

I didn't... exactly.

The problem with 5th field is that it breaks the convention of the separator being:

","

That leads to 4th field being:

1234567890",$189.93,"C"

Now, splitting that, using a "," with function 'split($4, a, ",")' will produce an array, named "a", with 3 fields:

a[1] = 1234567890"
a[2] = $189.93
a[3] = "C"

So, I just used a[2].

Nix.

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.