Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 08-24-2008, 01:10 PM   #1
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
indexing in awk....

I am a newbie in programming. I have learnt awk thru internet. I came to know that in cobol programmers use index files to get quick results(?) what is the use of index files(even i saw this indexing concept in FoxPro) can i use this method in Awk.. kindly explain me.
Old 08-25-2008, 09:26 AM   #2
Senior Member
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062
The AWK programming language doesn't really have any convenient way to do this; it probably can be done, but I think it would be a struggle that may not be worth the effort. There is a discussion at about AWK index files and an article introducing linked lists and index files at that may prove interesting.

An index file would contain information about the location (in another file, say) of indexed values. Essentially, the index would contain the address of one or more patterns in a data file that match the index criteria; that's a complicated way of saying "the stuff you want is at these addresses." In this case, "address" means an offset from the beginning of the data file; e.g., how many bytes in from the beginning of the file. Bear in mind that all files are just collections of bytes irrespective of what kind of data are stored (text, numeric, etc.). You can view a file in an editor, with a dump utility or by some other means -- you probably will be able to read the content of a text file but all others will look like gobbledygook. Different data types (character, integer, floating point) are stored in different sized fields from a single byte (for character) up to multiple bytes for floating point.

If I understand what it is you're trying to do, you may want to take a look at one of the relational data base management systems (DBMS); MySQL, PostrgeSQL and SQLite come to mind. Your system may already have MySQL installed, possibly PostgreSQL, maybe even SQLite; if not, it may be worth your while to install them from your distribution.

SQLite,, may be worth a look. It pretty much runs on anything, isn't a big chore to install, and gives you a fairly easy entry into the DBMS world. You can play around with creating tables and indexes without administrative duties to complicate things and, as time goes on, you can migrate what you've learned to MySQL or PostgreSQL (which do require administrative effort); one step at a time might be the way to go.

Once you struggle with "rolling your own" index method (been there, did that, don't want to do it again), you'll really appreciate what a RDBMS does for you. Give it some thought. Too, AWK is an interpreter, not a compiled language, and can be slow when working with large data sets (couple of hundred, not bad, couple of thousand, well...).

Hope this helps some.
Old 08-25-2008, 11:28 AM   #3
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
There is quite a big leap from indexed files to a full relational database. If all you want to do is relate some keys to values in a large set stored in a file, you are probably looking for something like the classic Unix DBM file format or one of the related implementations like GDBM.

Using these from awk is something I have never encountered, but it is commonly done in Perl with the "tie" feature. See "perldoc -f tie" for more info.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
awk question on handling *.CSV "text fields" in awk jschiwal Programming 8 05-27-2010 07:23 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM
indexing sathiyamoorthy Linux - Enterprise 1 03-05-2008 10:51 AM
Some comments on awk and awk scripts makyo Programming 4 03-02-2008 06:39 PM
CD Indexing ur-unholyness Linux - Software 1 01-11-2008 07:53 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:22 AM.

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