The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
parse through one text file and output many sophiadun UNIX for Dummies Questions & Answers 14 02-20-2008 06:08 AM
parse text file craggm Shell Programming and Scripting 9 02-27-2007 02:13 AM
Parse Text file and send mails Amruta Pitkar UNIX for Dummies Questions & Answers 12 08-11-2006 04:56 AM
How to parse a text file with \034 as field and \035 as end of message delimiter? indianya Shell Programming and Scripting 1 08-26-2005 10:20 PM
parse text or complex grep ? jacost UNIX for Dummies Questions & Answers 4 04-29-2004 08:58 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-15-2006
klick81 klick81 is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 2
parse text file

i am attempting to parse a simple text file with multiple lines and four fields in each line, formatted as such:

12/10/2006 12:34:06 77 38

this is what i'm having problems with in my bash script:

sed '1,6d' $RAWDATA > $NEWFILE
#removes first 6 lines from file, which are headers/unneeded
mv $RAWDATA $BACKUP
#saves untouched data file to backup
mv $NEWFILE $RAWDATA
#repositions data file (minus the 6 header lines) to the orginal filename
sed 144q $RAWDATA > $NEWFILE
#we only want the first 144 lines
sed = $NEWFILE | sed 'N;s/\n/\=/' > $RAWDATA
#number the lines (not sure if this is needed)
CURTEMP=`awk '/${LINENUM}=/ {print $3}' $RAWDATA`

everything works up until the last line. $LINENUM is set previously to 1 (first line). i'm brand new to scripting and 'awk' so i've probably screwed this all up. when i do the awk cmd from the command line without the variables it works. but when i run the script, this line return CURTEMP as blank.
the command line i use is
awk '/133=/ {print $3}' data.txt
and that works fine.. so not exactly sure where i went wrong, i just know that i went wrong. hopefully ya'll can straighten me out on this. thanks in advance
  #2 (permalink)  
Old 12-16-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
When you pass shell script variables to awk use one of these

Code:
CURTEMP=`awk '/"'"${LINENUM}"'"=/ {print $3}' $RAWDATA`

or

Code:
CURTEMP=`awk -v num=${LINENUM} ' $0 ~ num"=" {print $3}' $RAWDATA`

  #3 (permalink)  
Old 12-17-2006
klick81 klick81 is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 2
thanks! I tried both, the first option did not work. the second option got me a result, but it spits out 15 lines, instead of just one. what i need the script to do is this
read 1st line, take third field which is temperature
read 2nd line, take third field, compare to result from previous line, if higher, mark as MAX and move on to next line, if lower, just move on to next line.
read 3rd line, take third field, compare to result from previous line, if higher, mark as MAX and move on to next line, if lower, just move on to next line
etc... all the way through line 144 which would be the last line in the file. i have the script set to number the lines as such
1=time date temp humidity
2=time date temp humidity
....
144=time date temp humidity

any help is appreciated.. thank you!
  #4 (permalink)  
Old 12-18-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
What do you mean by "mark as MAX" ?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0