Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Tag Cloud
access acer asus bios bsod crash desktop driver drivers error ethernet excel freeze games gaming hard drive hardware hdmi internet laptop malware memory missing monitor motherboard network printer problem ram random registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
unix scripting help! grep with variable

Reply  
Thread Tools
denise_0006's Avatar
Member with 33 posts.
 
Join Date: Jun 2007
Experience: student
22-Nov-2009, 02:24 PM #1
unix scripting help! grep with variable
Hi
I have a file like this:
FirstName LastName:Address:Phone number
Using the : as delimiter

I want to add users to this file with the same info. how do i check if there is repetition?
just for the first name. i realized grep uses white space as delimiter.. but the full name with always have a white space!
i stored the full name in the variable FNAME
like this:
echo "Enter full name"
read FNAME

if [ -n "FNAME" ] then -- this means FNAME is not empty
for FN in `grep $FNAME in userinfo.txt | awk -F: '{print $1}'`

....
BODY
....

anyways, this will never be true for the grep part coz it treats the space as a different thing. and i want the full name

so i tried using two variables
FNAME for firstname and LNAME for lastname
...
...
for FN in `grep $FNAME?$LNAME.....` ......
or
for FN in `grep $FNAME[:space:]$LNAME ...`
or
for FN in `grep $FNAME[[:space:]]$LNAME ...`
or using double and single quotes in
for FN in `grep "$FNAME?$LNAME" ...` or '$FNAME?$LNAME '

all don't work.. HELP PLEASE
VERY MUCH APPRECIATED
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
30-Nov-2009, 09:07 AM #2
Been a while since I have done shell scripting, but your question may be better served in the Unix/Linux forum below.
You can report your post and ask to have the moderators move it to that category.

I guess I am not quite understanding how you want to check for repetition? Do you want to check to see if the full name is already there or do you just want to check for the first name is the same? Not sure if you need to put the delimiter in the AWK statement in single quotes.

I wouldn't necessarily say grep uses space as a delimiter. It will find stuff you are searching for inside other words.
Reply

Tags
unix grep

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:29 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.