LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-27-2013, 12:30 PM   #1
kishore79
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Rep: Reputation: Disabled
Unhappy Need help to write a script which picks values from textfile.


Hello folks,

Would anyone help me with this

I need to write a shell script which picks values from the textfiles.
If the entered parameter is not in the txtfile it should echo "does not exist".

Any suggestions are appreciated.
 
Old 12-27-2013, 12:42 PM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,977
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Depends on what you're trying to do...

Have you written anything yet? What part are you stuck on?

--C
 
Old 12-27-2013, 12:52 PM   #3
kishore79
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by custangro View Post
Depends on what you're trying to do...

Have you written anything yet? What part are you stuck on?

--C
If the parameter exists in the textfile then it should echo "welcome" otherwise it should echo "does not exist".


#!/bin/bash
echo "enter the name of the file"
if [ grep "$1" property.txt ]
then
echo "welcome" $1
else echo "Does Not Exist"
fi
 
Old 12-27-2013, 01:42 PM   #4
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,977
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
you can see how many instances of $1 appears in a file.

Code:
#!/bin/bash
[[ $# -eq 0 ]] && echo "Please enter a search string" && exit
mystring=$1
file=/tmp/property.txt
[[ ! -e ${file} ]] && echo "File not found" && exit
if [[ $( grep -ci ${mystring} ${file}) -eq 0 ]] ; then
   echo "Does Not Exist"
else
  echo "Welcome ${mystring}"
fi
##
##
 
Old 12-30-2013, 09:46 AM   #5
kishore79
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
custangro,

Thankyou very much. I really appreciate your help and time.

Thanks,
Kishore
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash: copy a whole textfile to write inside another textfile thecazz Programming 6 08-04-2013 03:16 PM
[SOLVED] bash script for separation a simple textfile potzkoten Programming 9 05-15-2012 10:48 AM
[SOLVED] Script to add up numbers in textfile philipz Programming 3 05-20-2010 09:38 AM
[SOLVED] how to find a word in a textfile starting from the BOTTOM of the textfile ? markraem Linux - Software 3 02-08-2010 07:12 AM
C prog..except input ,write to textfile?? kato678 Programming 1 02-21-2002 02:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration