LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux Script (https://www.linuxquestions.org/questions/linux-newbie-8/linux-script-633188/)

yusufs 04-05-2008 01:24 AM

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

carltm 04-05-2008 05:40 AM

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


yusufs 04-05-2008 06:49 AM

Quote:

Originally Posted by carltm (Post 3111520)
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

carltm 04-05-2008 07:06 AM

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

Code:

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

yusufs 04-05-2008 07:49 AM

Quote:

Originally Posted by carltm (Post 3111586)
Oops. I'm missing one part. It should be:

Code:

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




Thanks carltm , that really helped.


Yusuf


All times are GMT -5. The time now is 07:25 PM.