LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-18-2010, 10:25 AM   #1
Philip Kiser
LQ Newbie
 
Registered: Aug 2010
Posts: 2

Rep: Reputation: 0
awk delimiters


Hi,

Let me apologize in advance for the simple question.

I have the following text.

PHP Code:
1234567890123456789012

1  N   AAA  45  65 231
2  FGH AAA  40  541452
3  SGFEAAA  55  45 735
4  DSG BBB  62  54 552
5  GHH CCC  45  87 664 
The first line of numbers is to indicate the position of the text below. The text has six columns of information: A number that occupies positions 1-3,
a name that occupies positions 4-7, an alternative name that occupies positions
8-10 and three numbers that occupy positions 13-14, 17-18 and 19-22, respectively.

I would like to use awk to select records that have AAA as their
alternative name (records 1-3) and then calculate the sum of the
numbers that occupy positions 19-22 in these records (231+1452+735)
As you can see, some of the records are not separated by white space so
I can't use the default awk delimiter.

My question is how to set up the awk field delimiters to accomplish
this task.

Many thanks for your help.

Philip

Last edited by Philip Kiser; 08-18-2010 at 10:43 AM. Reason: forgot to add php tags
 
Old 08-18-2010, 10:48 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well awk is generally devised around having a constant delimiter, such as a space. Seeing as there is no real pattern and you wish to use
awk I would suggest setting it to empty which will then make every character equal to a field:
Code:
awk -F "" '<yourstuff>' file
Please note the space between the F and first inverted commas "
 
Old 08-18-2010, 10:57 AM   #3
Philip Kiser
LQ Newbie
 
Registered: Aug 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Grail,

Thanks a lot. I didn't know that was a possibility.

Best wishes,
Philip
 
Old 08-18-2010, 11:14 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
All good I find this site very useful
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I cut fields with repeated delimiters? Mountain Linux - Software 4 11-19-2012 07:50 AM
awk output delimiters casperdaghost Linux - Newbie 4 10-23-2009 08:17 AM
Simple (?) awk, two delimiters int0x80 Programming 3 02-25-2009 08:53 AM
Using Delimiters to get the end of the string champak Programming 3 12-16-2007 06:15 AM
Delimiters in control file ancys Programming 1 08-11-2006 11:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration