LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 07-30-2007, 09:50 AM   #1
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Rep: Reputation: 15
awk record separator question


Hi.

given a data file 'test' such as:

Code:
test1a test1b test1c
test2a test2b test2c
test3a test3b test3c
within awk I would like to treat each line as a separate field...

but
Code:
awk -v FS='\n' '{print $1}' test
does not give me what I expect. It outputs the entire file rather than the first line...
Code:
test1a test1b test1c
test2a test2b test2c
test3a test3b test3c
Code:
awk -v FS='\n' '{print $2}' test
gives me nothing...

I thought by setting the FS to newline, that test1a test1b test1c would become the first field,
test2a test2b test2c the second. and so on...

therefore I would expect
Code:
awk -v FS='\n' '{print $1}' test
to just give me:

Code:
test1a test1b test1c

Would appreciate if someone could point me in the right direction.
 
Old 07-30-2007, 10:24 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,805

Rep: Reputation: 324Reputation: 324Reputation: 324Reputation: 324
Your understanding of the difference between 'field' and 'record' seems to be part of the problem.

Each line is a record, made up of three fields, seperated by a space.

So, you need to print each line (record) of the file.
 
Old 07-30-2007, 10:35 AM   #3
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Original Poster
Rep: Reputation: 15
Thanks for the reply...

I'm doing this inside a bash while loop. Each record (entire line) is filtered through awk which will write the line to a temporary file...the values in this temporary file will then be passed to a separate program for calculations and so on...

I need awk to output each record as a single field for this purpose...so the problem remains

Code:
#!/bin/bash

i=1

while [ $i -le `wc -l preliminary.file | awk '{print $1}'` ] ; do


   awk  -v FS="\n" -v i="$i" '$1 == i {print $1}' preliminary.file > temp1.file

  read eq date otime elat elon depth mag sac_evt.file station residual error < temp1.file

                           etc.......                  

    i=`expr $i + 1`

done

Last edited by johnpaulodonnell; 07-30-2007 at 10:52 AM.
 
  


Reply


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 syntax to print particular record of xyz file? johnpaulodonnell Linux - Newbie 4 06-14-2007 08:47 AM
an awk question zoshr Programming 5 04-13-2007 06:29 AM
awk: How can I return a specified record dimsh Linux - Newbie 4 09-24-2005 12:36 PM
awk question puishor Programming 2 08-26-2005 10:44 AM
My field separator changes when using awk Helene Programming 3 05-01-2004 09:10 AM


All times are GMT -5. The time now is 07:32 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration