getline from another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getline from another file
# 1  
Old 10-14-2011
Question getline from another file

Here is I want to do:
find lines in file filteredtrace.txt which is not continued as
a multiply of 4 and strip them from file original_trace_framno.

problem is awk used the ' symbol
so pipe of getline has to use the " symbol
while agument of sed has to use the " symbol,
it doesn't recongize the ' symbol.
Code:
awk 'BEGIN{old=0}
{
    if(NR>5) 
    {   
        while($9>old&&$9-old!=4) 
        {   
            a=old*2+6; 
            print a;
            "'sed -n "${a}pi" original_trace_framno'"|getline al; 
            print al; 
            a++;
            "sed -n '${a}p' original_trace_framno"|getline al; 
            print al; 
            old +=4;
            exit
        }   
        if($9<=old)
            print $0; 
        else if($9>old&&$9-old==4) 
        {   
            old=$9;
            print $0
        }   
    }   
    else 
        print $0
}' 
filteredtrace.txt

part of original_trace_framno (vim with 'set nu' )
78 0x00009f7c 9 0 0 0 SliceData No No 40 0
79 0x00009f85 2976 0 0 0 SliceData No No 40 0
80 0x0000ab25 9 0 1 0 SliceData Yes No 38 0
81 0x0000ab2e 713 0 1 0 SliceData Yes No 38 0
82 0x0000adf7 8 0 2 0 SliceData Yes No 37 0
83 0x0000adff 383 0 2 0 SliceData Yes No 37 0
84 0x0000af7e 8 0 2 0 SliceData Yes No 39 0
85 0x0000af86 400 0 2 0 SliceData Yes No 39 0
86 0x0000b116 9 0 0 0 SliceData No No 44 0
87 0x0000b11f 2972 0 0 0 SliceData No No 44 0
88 0x0000bcbb 9 0 1 0 SliceData Yes No 42 0
89 0x0000bcc4 638 0 1 0 SliceData Yes No 42 0
90 0x0000bf42 8 0 2 0 SliceData Yes No 41 0
91 0x0000bf4a 415 0 2 0 SliceData Yes No 41 0
92 0x0000c0e9 8 0 2 0 SliceData Yes No 43 0
93 0x0000c0f1 325 0 2 0 SliceData Yes No 43 0
94 0x0000c236 9 0 0 0 SliceData No No 48 0
95 0x0000c23f 2568 0 0 0 SliceData No No 48 0

part of filteredtrace.txt (vim with 'set nu' )
38 0x00009f7c 9 0 0 0 SliceData No No 40 1317630108771
39 0x00009f85 2976 0 0 0 SliceData No No 40 1317630108771
40 0x0003f006 9 0 0 0 SliceData No No 352 1317630119121
41 0x0003f00f 977 0 0 0 SliceData No No 352 1317630119121
42 0x0003f537 9 0 0 0 SliceData No No 356 1317630119205
43 0x0003f540 1138 0 0 0 SliceData No No 356 1317630119205
44 0x0003fba4 9 0 0 0 SliceData No No 360 1317630119300
45 0x0003fbad 1300 0 0 0 SliceData No No 360 1317630119300
46 0x000402f0 9 0 0 0 SliceData No No 364 1317630119375

need to add lines which has $8 of 44 48 ... 348 from original_trace_framno to file filteredtrace.txt.
# 2  
Old 10-14-2011
What are those seds supposed to be doing? You know sed will only get run once, before awk even runs, not once per loop right?
# 3  
Old 10-14-2011
filteredtrace.txt
I have to modify the suffix to .txt
originaltrace-frameno.txt
# 4  
Old 10-14-2011
Quote:
Originally Posted by Corona688
What are those seds supposed to be doing? You know sed will only get run once, before awk even runs, not once per loop right?
I have to print 2 lines at one time for data processing reason.
# 5  
Old 10-14-2011
You answered me twice and still didn't really answer my questions... Modify what suffix? what is "a"? Is this supposed to change every loop or not?

Try getline <"filename.txt" instead of "something | getline".

Or better:

Code:
awk -v FILE="filename" '{ ...  getline < FILE }'

instead of embedding shell statements inside your awk statement.
# 6  
Old 10-14-2011
Quote:
Originally Posted by Corona688
You answered me twice and still didn't really answer my questions... Modify what suffix? what is "a"? Is this supposed to change every loop or not?

Try getline <"filename.txt" instead of "something | getline".

Or better:

Code:
awk -v FILE="filename" '{ ...  getline < FILE }'

instead of embedding shell statements inside your awk statement.
I modify the original_trace_framno to original_trace_framno.txt in order to upload the attachment.
"a" is described the relation between line number and $8(frame number) in file original_trace_framno.txt.
the change happened only when frame number is not contiued as a multiply of 4.
file filteredtrace.txt is genarated from original_trace_framno, with some of lines missing. During these missing lines, some are very important and need to be recovered from original_trace_framno. for example,
In file filteredtrace.txt line with $8==44 is missing, so I need to strip it from original_trace_framno.
# 7  
Old 10-14-2011
Quote:
Originally Posted by lzq420241
"a" is described the relation between line number and $8(frame number) in file original_trace_framno.txt.
Smilie I don't think that crossed the language barrier.

You can't call sed inside awk.

You can't pipe inside awk either.

---------- Post updated at 11:08 AM ---------- Previous update was at 11:06 AM ----------

Could you show the actual output you want too, not just your input files?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk with if, getline, and another if

Howdy Folks, It seems like it is always awk that confuses the heck out of me and I even have books and examples. I have this line: awk '{if (/clientIP/)(SRV = $NF); if ($2 ~ /BUNDLE-GIM/) getline; if ($2 ~ /r100595/) {print SRV,"BUNDLE-GIM",$2}}' post.txt to parse this text: <api... (4 Replies)
Discussion started by: port43
4 Replies

2. Shell Programming and Scripting

awk getline t file

I want to import a textfile with getline into var t which has several lines. How do import all lines, since it only imports the last line: while < ((getline t "textfile") > 0) (7 Replies)
Discussion started by: sdf
7 Replies

3. Shell Programming and Scripting

GetLine fn always giving last line of the file

Hi, Its bit urget for me to complete. pls help me. I am parsing 2 file 1. INDATA(Data file) 2. GRPFIL(Reference) every record in INDATA should be verified with GRP_DATA. I am seeing the output from only the last line of ref file, its not searching all the lines. INDATA sample... (1 Reply)
Discussion started by: hyperion.krish
1 Replies

4. Shell Programming and Scripting

awk print header as text from separate file with getline

I would like to print the output beginning with a header from a seperate file like this: awk 'BEGIN{FS="_";print ((getline < "header.txt")>0)} { if (! ($0 ~ /EL/ ) print }" input.txtWhat am i doing wrong? (4 Replies)
Discussion started by: sdf
4 Replies

5. Programming

getline()

I can not get 'getline()' to compile. I have tried. string curLine; //= compiler error char* curLine; //=compiler error char curLine; //=compiler error Every example I see uses a string as a getline(); parameter. It does not work for me on Fedora14 with gcc-c++. Thank you so much. This... (1 Reply)
Discussion started by: sepoto
1 Replies

6. Shell Programming and Scripting

awk - getline from parametric file name

Hi! I have an input file for an awk script that I need to split into several files and the process them separately line by line. I have splitted the input file into the other files, that have been created correctly. But, since their names are parametric (i.e. output_1.txt, output_2.txt..... (2 Replies)
Discussion started by: Alice236
2 Replies

7. Shell Programming and Scripting

Some Awk Getline help?

Greetings, I have about 3000 files that I want to search. The first column in all of these 3000 files has a unique serial number on each line. The subsequent columns have lots of data. I have another masterfile with three columns to help me find all the data I need in a moments notice: col 1... (15 Replies)
Discussion started by: jeeplou
15 Replies

8. Programming

'getline' questions

I have a C program I've written that includes a 'getline' call that is used to read a line at a time from a file and process the information in each line. A potential problem comes up since I don't know the maximum length of each line; right now I'm using a constant of 256, but that might not be... (2 Replies)
Discussion started by: cleopard
2 Replies

9. Shell Programming and Scripting

acessing awk array element while getline < "file"

I am attempting to write a awk script that reads in a file after awk array elements are assigned and using those elements while reading in the new file. Does this make sense? /pattern/ {tst=$3} (( getline < "file" ) > 0 ) { x=x " "tst } When I print tst in the END statement it... (9 Replies)
Discussion started by: timj123
9 Replies

10. Shell Programming and Scripting

using the getline to populate an array from a file

Hello, I am trying to use the awk getline command to populate an array from a flat file. Has anyone done this before? So we have file1: a b c d I want to create an array like index that contains these four elements (8 Replies)
Discussion started by: penfold
8 Replies
Login or Register to Ask a Question