Sponsored Content
Full Discussion: grep within while read loop
Top Forums Shell Programming and Scripting grep within while read loop Post 302364795 by migurus on Saturday 24th of October 2009 01:57:52 AM
Old 10-24-2009
grep within while read loop

I have a key file
$ cat klist
5 N:8855 CASA VERDE ROAD :32827 :ORLAND
5 N:585 MOLLY LANE :30189 :WOODST
5 N:320 NINA ROAD :32304 :TALLAH

and a data file, see example of the line below:

N:RT 15 & N 7TH STREET :17837 :U SAVE

I need to search by key (2nd field) from klist within mlist.
My code:

Code:
 
#!/bin/ksh
cut -d':' -f2 klist|while read addr; do 
        grep "'""$addr""'" mlist; 
done
exit 0

When I run the script nothing comes out. I used set -x in the script, see output below:

Code:
 
+ cut -d: -f2 klist
+ read addr
+ grep '8855 CASA VERDE ROAD' mlist
+ read addr
+ grep '585 MOLLY LANE' mlist
+ read addr
+ grep '320 NINA ROAD' mlist
+ read addr
+ exit 0

But when I manually run one of the grep the result is found:

Code:
 
$ grep '320 NINA ROAD' mlist
N:320 NINA ROAD                   :99999 :BARROW
N:320 NINA ROAD                   :32304 :TALLAH          
A:320 NINA ROAD                   :32304 :TALLAH

I suspect the input/output streams being messed up whithin the while read loop, but have no clear understanding of the problem. Can someone clarify the situation, please?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

read inside a while loop

Hi all, In a while loop, like below... while read line do read choice case $choice in 1) echo "xxx" esac done < file why I can't run the read choice???? (3 Replies)
Discussion started by: dta4316
3 Replies

2. Shell Programming and Scripting

Need Help : while read loop

hi all, Can you please help me with this issue ? while ####infinite loop do cat file1 |while read var1 var2 do func1 $var1 $var2 done cat file2 | while read var11 var22 do func2 $var11 $var22 done done func1 is called till all the values are read... (2 Replies)
Discussion started by: Navatha
2 Replies

3. Shell Programming and Scripting

read line in a for loop

Hi All, How can we use read line using the index value of a FOR loop? eg: pt_mstr,pt_status,8 pt_mstr,pt_buyer,8 pt_mstr,pt_sfty_stk,8 pt_mstr,pt_ord_pol,3 pt_mstr,pt_capacity,8 pt_mstr,pt_plan_ord,3 pt_mstr,pt_ord_mult,8 From this file i want to read the line2, 3 and 4 only using a FOR... (3 Replies)
Discussion started by: balajim
3 Replies

4. Shell Programming and Scripting

Need help with for loop with while read

Hello, The code below pulls printer information from a three-column file (set by the ${MULTIFILE} variable at the end), that has the printer queue name, IP, and type of printer. It is supposed to use this info to add the printers in the list to one, or more servers . The input file... (3 Replies)
Discussion started by: LinuxRacr
3 Replies

5. Shell Programming and Scripting

While read line loop

Hi I'm writing a bash script which will read an input file and look for occurrences of the current user ($USER) executing the script. When i find the occurrence of the username I take that line and append it to a file with a line number and bracket display next to line. The input file has been... (12 Replies)
Discussion started by: BundBash
12 Replies

6. Shell Programming and Scripting

until loop and read

Hi guys what I wanna do is to create a script where can I input several times a file - assume with read function that will be inserted into a temp. file for further processing. When I press q I want that the loop will stop and continue in my script I typed this but the options q is not working... (6 Replies)
Discussion started by: kl1ngac1k
6 Replies

7. UNIX for Dummies Questions & Answers

Read statement within while read loop

hi, this is my script #!/bin/ksh cat temp_file.dat | while read line do read test if ]; then break else echo "ERROR" fi done when i execute this code , the script does wait for the user input . it directly prints "ERROR" and terminates after the no. of times as there... (3 Replies)
Discussion started by: siva1612
3 Replies

8. Shell Programming and Scripting

Help with while read loop

Hey all, Tried searching the forums but my search-fu may not be strong today; please feel free to redirect me if I have simply missed a post that would be helpful! Trying to create a while loop that reads a list of configuration files, checks for a line that starts with "SOME_CMD" and ends... (4 Replies)
Discussion started by: jdwyer
4 Replies

9. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

10. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies
klist(1)							   User Commands							  klist(1)

NAME
klist - list currently held Kerberos tickets SYNOPSIS
/usr/bin/klist [-e] [ [-c] [-f] [-s] [ -a [-n]] [cache_name]] [ -k [-t] [-K] [keytab_file]] DESCRIPTION
The klist utility prints the name of the credentials cache, the identity of the principal that the tickets are for (as listed in the ticket file), and the principal names of all Kerberos tickets currently held by the user, along with the issue and expiration time for each authenticator. Principal names are listed in the form name/instance@realm, with the '/' omitted if the instance is not included, and the '@' omitted if the realm is not included. If cache_file or keytab_name is not specified, klist will display the credentials in the default credentials cache or keytab files as appropriate. By default, your ticket will be stored in the file /tmp/krb5cc_uid, where uid is the current user-ID of the user. OPTIONS
The following options are supported: -a Displays list of addresses in credentials. Uses the configured nameservice to translate numeric network addresses to the associated hostname if possible. -c [cache_name] Lists tickets held in a credentials cache. This is the default if neither -c nor -k is specified. -e Displays the encryption types of the session key and the ticket for each credential in the credential cache, or each key in the keytab file. -f Shows the flags present in the credentials, using the following abbreviations: A preAuthenticated F Forwardable f forwarded P Proxiable p proxy D postDateable d postdated R Renewable I Initial i invalid -k [keytab_file] List keys held in a keytab file. -K Displays the value of the encryption key in each keytab entry in the keytab file. -n Shows numeric IP addresses instead of reverse-resolving addresses. Only valid with -a option. -s Causes klist to run silently (produce no output), but to still set the exit status according to whether it finds the credentials cache. The exit status is ` 0' if klist finds a credentials cache, and ` 1' if it does not. -t Displays the time entry timestamps for each keytab entry in the keytab file. ENVIRONMENT VARIABLES
klist uses the following environment variable: KRB5CCNAME Location of the credentials (ticket) cache. See krb5envvar(5) for syntax and details. FILES
/tmp/krb5cc_uid Default credentials cache (uid is the decimal UID of the user). /etc/krb5/krb5.keytab Default location for the local host's keytab file. /etc/krb5/krb5.conf Default location for the local host's configuration file. See krb5.conf(4). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWkrbu | +-----------------------------+-----------------------------+ |Interface Stability | See below. | +-----------------------------+-----------------------------+ The command arguments are Evolving. The command output is Unstable. SEE ALSO
kdestroy(1), kinit(1), krb5.conf(4), attributes(5), krb5envvar(5), SEAM(5) BUGS
When reading a file as a service key file, very little error checking is performed. SunOS 5.10 30 Apr 2004 klist(1)
All times are GMT -4. The time now is 06:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy