l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
November 4: Social gathering
Next Installfest:
TBD
Latest News:
Oct. 10: LUGOD Installfests coming again soon
Page last updated:
2006 Aug 21 14:19

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] awk and multi-line records
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] awk and multi-line records



so it looks like my simple approach to dealing with some files, that normally 
contain single-line records, breaks when they decide to use multiline records 
some of the time.... 

the nature of the data is something like this:

fixed number of columns, with '|' delimiter:
 col 1| col 2 | col 3 | ... col_n 
 col 1| col 2 | col 3 | ... col_n 
 col 1| col 2 | col 3 | ... col_n 
 col 1| col 2 | col 3 | ... col_n 

some of the time one of these columns will contain multi-line text:

col 1| col 2 | col 3 |
blah blah blah ... 
blah blah blah ...
blah blah blah ...
blah blah blah ...
blah blah blah ... | ... col_n 

(!)

I was using a simple awk script to add an extra column to each record as 
follows:

awk -v areasymbol=$areasymbol '{gsub("\"","") ; print ""areasymbol"|"$0}' 
input-table > output-table
...
newco | col 1| col 2 | col 3 | ... col_n 
newcol | col 1| col 2 | col 3 | ... col_n 
...

the question is then: 

is there any simple way to "add" a column to this kind of flat text file using 
awk when there is:

1. consistent field delimeters
2. consistent number of fields
3. inconsistent records delimiters

thoughts? 

PS: this is being used to prep. some data for loading into PGSQL with the COPY 
command.

Cheers,





-- 
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.