parse text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parse text file
# 1  
Old 12-15-2006
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  
Old 12-16-2006
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  
Old 12-17-2006
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  
Old 12-18-2006
What do you mean by "mark as MAX" ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse file for fields and specific text

I have a file of ~500,000 entries in the following: file.txt chr1 11868 12227 ENSG00000223972.5 . + HAVANA exon . gene_id "ENSG00000223972.5"; transcript_id "ENST00000456328.2"; gene_type "transcribed_unprocessed_pseudogene"; gene_status "KNOWN"; gene_name "DDX11L1"; transcript_type... (17 Replies)
Discussion started by: cmccabe
17 Replies

2. Shell Programming and Scripting

awk to parse file and display result based on text

I am trying using awk to open an input file and check a column 2/field $2 and if there is a warning then that is displayed (variantchecker): G not found at position 459, found A instead. The attached Sample1.txt is that file. If in that column/field there is a black space, then the text after... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

Parse text file using specific tags

awk -F "" '/<href=>|<href=>|<top>|<top>/ {print $3, OFS=\t}' source.txt > output.txt I'm not quite sure how to parse the attached file, but what I am trying to do is in a output file have the link (href=), name (after the <), and count (<top>) in 3 separate columns. My attempt is the above... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

script to parse text file into sql commands

Hello all, I tried searching for something similiar before posting but couldn't come up with anything that fit what I need. In Linux, I'm trying to parse through a number of files and take the info in them and put it into mysql. My file is a dump from an expect script: ---filename... (3 Replies)
Discussion started by: hamanjam
3 Replies

5. Shell Programming and Scripting

Parse and Join in a text file

I wanted to parse a text file and join in specific format. please suggest me how to get this done.. The output should be in fasta format which consists of lines starting with ID, PT, PA and Sequence. "//" the two slashes are dividing lines between two different sequences. Like... (10 Replies)
Discussion started by: empyrean
10 Replies

6. Shell Programming and Scripting

How to parse a file for text b/n double quotes?

Hi guys, I desperately need some help here... I need to parse a file similar to this: I need to read the values for MY_BANNER_SSHD and WARNING_MESSAGE. The value could be empty/single line or multi-line! # Comments . . . Some lines MY_BANNER_SSHD=""... (7 Replies)
Discussion started by: shreeda
7 Replies

7. Shell Programming and Scripting

Trying to Parse Version Information from Text File

I have a file name version.properties with the following data: major.version=14 minor.version=234 I'm trying to write a grep expression to only put "14" to stdout. The following is not working. grep "major.version=(+)" version.properties What am I doing wrong? (6 Replies)
Discussion started by: obfunkhouser
6 Replies

8. UNIX for Dummies Questions & Answers

parse through one text file and output many

Hi, everyone The input file pattern is like below: Begin Object1 txt1 end ; Begin Object2 txt2 end ; ... (14 Replies)
Discussion started by: sophiadun
14 Replies

9. Shell Programming and Scripting

parse text file

I have a file that has a header followed by 8 columns of data. I want to toss out the header, and then write the data to another file with a different header and footer. I also need to grab the first values of the first and second column to put in the header. How do I chop off the header? ... (9 Replies)
Discussion started by: craggm
9 Replies

10. UNIX for Dummies Questions & Answers

Parse Text file and send mails

Please help. I have a text file which looks something like this aaa@abc.com, c:FilePath\Eaaa.txt bbb@abc.com, c:FilePath\Ebbb.txt ccc@abc.com, c:FilePath\Eccc.txt ddd@abc.com, c:FilePath\Eddd.txt...so on I want to write a shell script which will pick up the first field 'aaa@abc.com' and... (12 Replies)
Discussion started by: Amruta Pitkar
12 Replies
Login or Register to Ask a Question