getline value to pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers getline value to pattern
# 1  
Old 11-07-2010
getline value to pattern

BEGIN {
system("clear")
blank = " "
printf("Please enter your name or emp# : > ")
getline < "/dev/tty"
printf(">>>>> %s",$1)
}

/$1/ {..........

I would like for the customer to enter name or whatever and use that input as the search pattern. The printf displays the input entered correctly - but $1 value is not being used. How do I correctly specify the $1 value to be used as the search argument?

I am only using awk or nawk.
# 2  
Old 11-07-2010
Something like this?
Code:
getline var < "-"
printf(">>>>> %s", var)

$0 ~ var {...}

# 3  
Old 11-08-2010
It seems to work except that the $0 ~ var statememt appears to be finding lines with everthing that is in var. From the terminal 'will' is entered.
The lines returned are ones which contain a w or i or l or l. I need it to find lines that only contain will. I really would like it to search like this $0 ~ \<var\>.

Thanks
# 4  
Old 11-08-2010
Quote:
Originally Posted by Morph797
It seems to work except that the $0 ~ var statememt appears to be finding lines with everthing that is in var. From the terminal 'will' is entered.
The lines returned are ones which contain a w or i or l or l. I need it to find lines that only contain will. I really would like it to search like this $0 ~ \<var\>.

Thanks
It should work, this is what I get with this example:
Code:
$ cat file
will 123
lliw 456
wil l
$ 
$ awk 'BEGIN{printf("Enter the pattern: ");getline var < "-"}
$0 ~ var {print "The line contains: " $0}' file
Enter the pattern: will
The line contains: will 123
$

This User Gave Thanks to Franklin52 For This Post:
 
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. Programming

getline() and fclose()

Hi All, When I do man getline on my Linux system (in BASH), I see an example C code where a file is being read using getline() function. Now, my question is why there is no fclose() to close the open file pointer? People who don't have a Linux system, this is the code that I am referring... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

3. Shell Programming and Scripting

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... (8 Replies)
Discussion started by: lzq420241
8 Replies

4. Shell Programming and Scripting

nawk getline

I'm running the script below and get the output below against a file with lineA=aaa lineB=bbb lineC=ccc lineD=ddd I get output: lineC=ccc lineD=ddd I need the output to be: lineB=bbb lineC=ccc lineD=ddd cat filename | nawk '/lineA=aaa/ { getline; do { getline (3 Replies)
Discussion started by: toor13
3 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

Using getline in awk

I am using awk and want to use getline from a file like below getline x < file However file consists of two columns and I only want to store $2 Any way I can do this? ---------- Post updated at 06:54 AM ---------- Previous update was at 06:45 AM ---------- Done something like this.... (1 Reply)
Discussion started by: kristinu
1 Replies

7. Shell Programming and Scripting

awk getline

How do you make the getline function return to the original line? The example below should make it clear where I am currently going wrong. Thanks AWK SCRIPT: ------------- awk -F '-' '{ tmpLine = "EMPTY" print "CURRENT LINE :"$0 getline tmpLine print "NEXT LINE :"tmpLine }'... (1 Reply)
Discussion started by: garethsays
1 Replies

8. Shell Programming and Scripting

awk getline help maybe?

hello collegues, I am attempting to use awk to search file1 (serverlist.csv) from each row with file2 (supported.txt). If the is no entry exists in serverlist then output to a file called notsupp.out if there is an entry output to supp.out I can do this with basic shell scripting however... (0 Replies)
Discussion started by: chlawren
0 Replies

9. UNIX for Dummies Questions & Answers

utility of getline here?

hi , I got a script that I don't understand. awk '{ command="echo "$1 command | getline echome close(command) print $0 "\t" echome }' < user.list It reads the file user.list user.list London John Bridge Peter and sends the stream to the awk command. I don't understand what is... (3 Replies)
Discussion started by: remid1985
3 Replies

10. Shell Programming and Scripting

getline with a unique

I have an inputfile that I trying to awk with a getline(Solaris v8 ksh). However I need to have the results be a unique. Is there a comparable command within awk to return a unique result? Or can you break out of the awk to add a uniq. I am looking for something more complex then a pipe... (6 Replies)
Discussion started by: gozer13
6 Replies
Login or Register to Ask a Question