LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 04-05-2008, 01:24 AM   #1
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Rep: Reputation: 30
Linux Script


Hai all,



1) I want to find out 'ora" from a <test> file wich contains data as follows:-

oracle
oraman
orgrp
oragrp
oracmon


When cat filename | grep ora command is issued, it shows the complete world which contains ora.. is there anyother way, we can fetch only "ora" from that..



2) am writing a script such that the user should enter username and password, but , if the username is not entered and user tries to move on to password , when <ENTER> is pressed without entering username , user should get the message saying that "USERNAME SHOULD BE ENTERED".. IIn Foxpro, this can be acheived by using EMPTY CHECK ....Tried the following :

stored input in a variable called “uname”
and stored uname in a temp file called “test1”
Given a command # a=`wc –c /test1`
If it is a=0 message will displays, >0 then comes to next field:
But it is not working..


Any help on the above is highly appreciated..


Thanks
Yusuf
 
Old 04-05-2008, 05:40 AM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
Here is a way to find and print the string "ora".

Code:
sed 's/.*ora.*/' filename | grep ora
Here is a way to get a valid username.

Code:
Valid=no
until [ "$Valid" = yes ]
do
  echo -n "Please enter username: "
  read UserName
  if grep "^$UserName:" /etc/passwd >/dev/null
  then Valid=yes
  else echo $UserName is not valid.
  fi
done
 
Old 04-05-2008, 06:49 AM   #3
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by carltm View Post
Here is a way to find and print the string "ora".

Code:
sed 's/.*ora.*/' filename | grep ora
Here is a way to get a valid username.

Code:
Valid=no
until [ "$Valid" = yes ]
do
  echo -n "Please enter username: "
  read UserName
  if grep "^$UserName:" /etc/passwd >/dev/null
  then Valid=yes
  else echo $UserName is not valid.
  fi
done



Thanks Carl,


script works fine. but not the sed command..

[oradev@oracle datas]$ cat new.txt

oracle
proalc
porat
lorat
gorak
forak


oradev@oracle datas]$ sed 's/.*ora.*/' new.txt | grep ora
sed: -e expression #1, char 10: unterminated `s' command


Your help is highly appreciated.

Thanks
Yusuf
 
Old 04-05-2008, 07:06 AM   #4
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
Oops. I'm missing one part. It should be:

Code:
sed 's/.*ora.*/ora/' filename | grep ora

Last edited by carltm; 04-05-2008 at 07:08 AM.
 
Old 04-05-2008, 07:49 AM   #5
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by carltm View Post
Oops. I'm missing one part. It should be:

Code:
sed 's/.*ora.*/ora/' filename | grep ora



Thanks carltm , that really helped.


Yusuf
 
  


Reply



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
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 02:41 AM
where to get linux administrator script, ex: script to let's user change user info. hocheetiong Linux - Server 1 03-17-2008 12:06 AM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 04:21 PM
Exp. Windows/Linux-Script Programmer - Need Linux Programming Mentor! ruttiger Linux - Newbie 2 10-28-2001 11:00 AM

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

All times are GMT -5. The time now is 03:58 PM.

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
Open Source Consulting | Domain Registration