nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Shell Script Searching For a Record In The File

This is a discussion on Shell Script Searching For a Record In The File within the Shell scripting forums, part of the Development/Scripting category; im trying to display a record... the user has to enter the ***** number to search for n then my ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-11-2008, 03:44 PM
Junior Member
User
 
Join Date: May 2008
My distro: Zero_Cool
Posts: 1
Rep Power: 0
vinz4ever is on a distinguished road
Question Shell Script Searching For a Record In The File

im trying to display a record... the user has to enter the ***** number to search for n then my script should look for any record with tht number n then display the whole record...
my data file is somthing like this :

9000232 Deo Vik V Media Technician 12/05/2002
9998765 Cassy John M Reporter News 12/08/2001
...
.
..
..
..............



the user will enter a number or maybe just part of it [not the whole number] n then the program should look for tht matching numbers, if any found then display tht on the screen... the whole record...


so if user enters 9000232 then the program should then print :

9000232 Deo Vik V Media Technician 12/05/2002

can someone pliz pliz help...

thanx you in advance....
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-11-2008, 07:35 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 919
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Try grep command
Code:
grep -e '^9000232' /path/to/file
A sample script:
Code:
#!/bin/bash
number=$1
FILE="/path/to/file"
if [ $# -eq 0 ]
then
   echo "$0 number"
   exit 1
fi

if [ ! -f $FILE ]
then
   echo "$FILE - not a file"
   exit 2
fi
grep -e "^${number}" ${FILE}
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks

Tags
grep , linux , shell script , unix


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Shell Script to Automatically Delete a File via Cron Job kakarla Shell scripting 2 01-29-2008 08:54 AM
shell script for ftp the file vishal_titre Shell scripting 3 12-10-2007 08:40 AM
Shell script to delete a file with a dialog utility shankar100 Shell scripting 4 03-02-2007 10:22 AM
error shell script no such file or directory /bin/sh Linux software 1 01-08-2006 08:34 PM
searching for bad words script marinm Shell scripting 1 02-03-2005 04:32 PM


All times are GMT +5.5. The time now is 10:58 PM.


Powered by vBulletin® Version 3.7.3 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36