Search name and display column from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search name and display column from a file
# 1  
Old 01-31-2010
Search name and display column from a file

Hi I have search everywhere for this but I haven't got any result. so here is my question?
I am trying to ask user to enter a name and then searching that name from a file and from a specific column. If user enter something, it should only displaying that name from that specific column and If the user enters quit, then program should quit. I am really having trouble with this. Any help will be appreciate.
Code:
echo "Name:"

while read name
do
        if  [ $name=0 ]
      then
          echo $name < filename
          cut -c 5-19 filename
           #echo "name is $name."
        elif [ $name = "Quit" ]
        then 
     exit       
fi
done


Last edited by Scott; 01-31-2010 at 09:13 PM.. Reason: Please use code tags
# 2  
Old 01-31-2010
Change the if loop to first check the Quit condition else it goes to get the content from the file
# 3  
Old 01-31-2010
Oh thanks but do you know how to write IF statement to find name? I am just going crazy Smilie
# 4  
Old 01-31-2010
If your requirement is to find a name in the file as a success condition then you can try this

Code:
while read name
do
        #if [ `echo $name < abc.txt` ]
        if [ `grep $name abc.txt` ]
        then
                echo "$name matches \n"
        elif [ $name = "Quit" ]
        then
                exit;
        fi
done

Also if a name does not match and you have some action intended for that as well then add an else loop

HTH,
PL
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to compare 3rd column value with first column and display

Hello Team, My source data (INput) is like below EPIC1 router EPIC2 Targetdefinition Exp1 Expres rtr1 Router SQL SrcQual Exp1 Expres rtr1 Router EPIC1 Targetdefinition My output like SQL SrcQual Exp1 Expres Exp1 Expres rtr1 Router rtr1 Router EPIC1 Targetdefinition... (5 Replies)
Discussion started by: sekhar.lsb
5 Replies

2. Shell Programming and Scripting

Search string in multiple files and display column wise

I have 3 files. Each of those files have the same number of records, however certain records have different values. I would like to grep the field in ALL 3 files and display the output with only the differences in column wise and if possible line number File1 Name = Joe Age = 33... (3 Replies)
Discussion started by: sidnow
3 Replies

3. Shell Programming and Scripting

Search first file line after Error and display

I have a log file which contains information like below (more than 200 ERROR sets). Here I want to find first .c file and function after "ERROR: AddressSanitizer" line. If you see here after "ERROR:" line first file - asfrecohandling.c function - ASFPotRecoHandling_Create_RecPaxSrvcComp ... (6 Replies)
Discussion started by: pushpabuzz
6 Replies

4. Shell Programming and Scripting

Search substring in a column of file

Hi all, I have 2 files, the first one containing a list of ids and the second one is a master file. I want to search each id from the first file from the 5th col in the second file. The 5th column in master file has values separated by ';', if not a single value is present. Each id must occur... (2 Replies)
Discussion started by: ritakadm
2 Replies

5. Shell Programming and Scripting

How to search for file and display by date

I like "ls -ltr". I would like to search for a file in a large directory recursively and and display all the candidates in reverse order. /usr/bin/find . -name \*.txt This works. How do I display the date and sort the file names by the date in reverse order for the entire directory... (1 Reply)
Discussion started by: siegfried
1 Replies

6. Shell Programming and Scripting

How to display the first column in a file?

Hi I need to dispaly only the first column from f1le1 . But i am unable to do with the cut option . Please help me . The File1 contains the below deatils : 2407765|xyz|774085264795|ABC|2522925531|60.0|01/09/10|CODE1 2408327|xyz|578981547385|ABC|2257881870|60.0|01/09/10| CODE2... (5 Replies)
Discussion started by: isha_1
5 Replies

7. Shell Programming and Scripting

Search in file and display

Dear All I had below mention requirement. Kindly sugguest me possible ways. Thanks Regards Jaydeep IN PUT FILE: CELL BROADCAST SHORT MESSAGE SERVICE MESSAGE DATA ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES 50 1000 0 13 MML 1 1 TEXT PAGE *999*1# SONGS4U@30/M- 1 (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies

8. Shell Programming and Scripting

Search from file and display

Dear all I had input file as mention below. From that i want op as given below. Kindly let me knw possible ways. Regards Jaydeep CONNECTED bscaaa <rxmfp:mo=RXOTX-46-5 ; RADIO X-CEIVER ADMINISTRATION MANAGED OBJECT FAULT INFORMATION MO BTSSWVER RXOTX-46-5 ERA-G04-R11-V01 ... (5 Replies)
Discussion started by: jaydeep_sadaria
5 Replies

9. Shell Programming and Scripting

Search from file and display

Dear All I had input file as mention below. Now from that file i want to search string "FAULT CODES CLASS" and want to display contain again its. ( ie. 1B4 --4 is in next line. ). Kindly let me know the possible ways. <rxmfp:mo=RXOTX-46-5 ; ... (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies

10. Shell Programming and Scripting

Help: for display the 1 column from one file?

Hi, boss i have a problem: i want display one column from a file. so i think i can used the awk -F"," '{print $number}' XXXX. but the file contain lots of the column,,,so i can confirm the line number which i need . so can some body help me to solve this issus....... PS: how can i... (5 Replies)
Discussion started by: surainbow
5 Replies
Login or Register to Ask a Question