Finding first and last name in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding first and last name in a file
# 1  
Old 10-25-2017
Finding first and last name in a file

We have a file containing names that we have to look up from time to time. The relevant part of the record looks like:
Code:
123@"DOE, John"@"indiv

The first and last names are positional parameters and so far my script looks like:
Code:
grep -i $2, myfilename |grep -i "', $1'" |more;

The first part of the script is OK, but I haven't found a way to put a leading space or ", " in front of the 2nd search expression that works. I've tested the 2nd part with
Code:
echo "', $1'"

, but that doesn't work in the last grep command.

Any ideas? TIA
# 2  
Old 10-25-2017
What do you need the single quotes for? Did you try without?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 10-25-2017
Thank you, that worked!
# 4  
Old 10-25-2017
Wouldn't
Code:
grep -i "$2, $1" file

work as well?
# 5  
Old 10-25-2017
Quote:
Originally Posted by RudiC
Wouldn't
Code:
grep -i "$2, $1" file

work as well?
It didn't fly. Replaced grep with echo. The name was formatted but not enclosed in quotes. Tried different combinations of single or double quotes on the outside, but nothing happened.

Thanks for looking, though.
# 6  
Old 10-26-2017
RudiC's solution works OK for me here:

Code:
$ cat name.find
grep -i "$2, $1" name.list

$ cat name.list
123@"DOE, John"@"indiv

$ ./name.find john doe
123@"DOE, John"@"indiv

$./name.find jane plain

# 7  
Old 10-26-2017
To keep from getting false positives (Chubler_XL and RudiC, try your suggestion with $1 set to OE and $2 set to Jo with your test dataset) by actually matching the double quotes in the file, one could try:
Code:
grep -i "\"$1, $2\"" myfilename

or, if you want a case sensitive match:
Code:
grep "\"$1, $2\"" myfilename

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding specific string in file and storing in another file

Text in input file is like this <title> <band height="21" isSplitAllowed="true" > <staticText> <reportElement x="1" y="1" width="313" height="20" key="staticText-1"/> <box></box> <textElement> <font fontName="Arial" pdfFontName="Helvetica-Bold"... (4 Replies)
Discussion started by: aankita30
4 Replies

2. Shell Programming and Scripting

Finding a file process ?

Hi, I am trying to find a file that have a different name than it should be processing, the file name is ( Fifa15 ) is there a command to use? I got that file by ps -ef | grep fifa15 but how do I know what is running ? thanks a lot, I am learning unix so sorry if that is a... (2 Replies)
Discussion started by: latinooo
2 Replies

3. UNIX for Dummies Questions & Answers

Need help finding a file where a pattern exists and the file has a timestamp

So, I know how to do some of this stuff on an individual level, but I'm drawing a blank as to how to put it all together. I have a pattern that I'm looking for in a log file. The log file I know came in yesterday, so I want to limit the search to that day's listing of files. How would I do... (5 Replies)
Discussion started by: kontrol
5 Replies

4. Shell Programming and Scripting

Extracting file name and finding extension of the file

Hi., How to extract the extension of a file which are present in the directory?. In my script I tried something like: echo abc_ss_222_54.txt | awk -F"" '{print $5}' But I din't got .txt echoed in console. Pl. suggest a solution for this. And also, for finding a specific... (1 Reply)
Discussion started by: IND123
1 Replies

5. Shell Programming and Scripting

Need help in finding filesize , moving file , gzipping file

Hi , Please help with the following questions 1) how can i find size of a file ? i have written du -k $flname > s1 . Is this right ? Any other better suggeastions ? 2) how do I use mv command for moving the file ? I need the syntax with some examples 3) Command for printing the total... (1 Reply)
Discussion started by: Learning!
1 Replies

6. Shell Programming and Scripting

Ksh - finding pattern in file and generating a new file

I am trying to find for the pattern in first 5 bytes of every line in a text file and then generate a new file with the pattern found. Example: expected pattern is '-' to be serached in first 5 bytes of file only. Input File ab-cd jan-09 ddddd jan09 cc-ww jan09 dsgdq jan-09 ... (2 Replies)
Discussion started by: net
2 Replies

7. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

8. Shell Programming and Scripting

awk script required for finding records in 1 file with corresponding another file.

Hi, I have a .txt file (uniqfields.txt) with 3 fields separated by " | " (pipe symbol). This file contains unique values with respect to all these 3 fields taken together. There are about 40,000 SORTED records (rows) in this file. Sample records are given below. 1TVAO|OVEPT|VO... (2 Replies)
Discussion started by: RRVARMA
2 Replies

9. UNIX for Advanced & Expert Users

finding a string in a file

hi all.. I dont know how to search for a string in a file.. I have tried doing.. I did google but didnt get effective answers..my code is as follows: int search(char* filename,const char* username,const char* passwd) { int flag=0; unsigned long fsize=0; unsigned long current=0;... (2 Replies)
Discussion started by: Ume1986
2 Replies

10. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question