Use of grep within scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of grep within scripts
# 1  
Old 04-06-2009
Use of grep within scripts

Hello,

I used the command (to see all names staring with a):
cleartool lsview -short | grep ^a, it works fine, but when I used the same command within script, didn't work.

Also I wanted to see names starting with a and A, how can I use the command.

Any advise is greatly appreciated.

abdurrouf
# 2  
Old 04-06-2009
What do you mean by it "didn't work"? Give us some information Smilie
You can match "a" and "A" with grep's -i parameter for case-insensitivity.
# 3  
Old 04-06-2009
Hi,

I hope this command can help you for your search:

grep -e "[a-A]" <filename>

But, grep ^a, will ignore the letter starting with a, and will show all other letter in the file.
# 4  
Old 04-06-2009
He is using a pipe to transfer the input to grep. Furthermore, your pattern isn't suitable for his problem as he wants to match filenames starting with either "a" or "A". The circumflex character in this particular context indicates the beginning of the filename string and is not a negating operator (That is the case, when put in front of a group of characters as in "[^a]". Actually, this doesn't have any effect with grep Smilie Anybody any idea why?

Last edited by Gunther; 04-07-2009 at 06:55 PM..
# 5  
Old 04-06-2009
Thank you Gunther & gsiva, here is more clarification of my requirement:
The output of "ct lsview -s" command is (example):
agutierr_EPASUE
Arajurka_CTI_Source_Rel_2.0_Integration
bbaldwin_bbaldwin_JSPTagLib_Rel_2.2.2_Project
vpurohit_ResultsReview_Rel_2.0_Project_int
apathy_PAA_Alaka_Testing_2
mkrishna_AOL_VAJava_1.1.8_Project_DEV3
mkrishna_AOL_VAJava_1.1.8_Project_DEV_int
mchezhia_CTI_Rel_1.0_Project_3_int
abharade_CTI_Rel_1.0_Project_int
Awilkin3_Trial
bbaldwin_JSPTagLib_Rel_2.2.2_Project_int
bbaldwin_JSPtag2_2
bbaldwin_JSPTagLib_Rel_2.2.2_Project_Integration

from I've to grab the lines staring with a & A, if I use the command

ct lsview -s | grep ^a

This works, but when I use this command in a script, then didn't work, here is the script part example:

$access_info="view_infoa.csv"; # Output file

# list of views on s199ap700
@view_lista = `cleartool lsview -short | egrep ^a`;

# for each view, do a full properties
# and get the appropriate information
open (ACCESS_INFO, ">$access_info") || die "Cannot open/create output file $access_info.";
$num_of_views=@view_lista;
print(ACCESS_INFO "SHORT NAME,OWNER,LAST ACCESS DATE,LAST ACCESS TIME,LAST ACCESS USER\n");
for ($i=0;$i < $num_of_views; $i++)
{
@description = `cleartool lsview -full -properties @view_lista[$i]`;
$len_of_desc=@description;


Any help is greatly appreciated.
# 6  
Old 04-06-2009
Code:
@view_lista = `cleartool lsview -short | egrep '^a'`;

i.e. put ^a in quotes ' '
# 7  
Old 04-07-2009
Thank you so much pmm! I greatly appreciate your help that really helped me lot since I'm novice in scripting, somehow ' ' didn't work but " " works.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling multiple scripts from another scripts

Dear all, I am working on script which call other shell scripts in a loop but problem is from second script am not able to come out. Here is the snippet:- #!/bin/bash HSFILE=/root/Test/Components.txt LOGFile=/opt/domain/AdminDomain/application/logs... (3 Replies)
Discussion started by: sharsour
3 Replies

2. OS X (Apple)

Need Help with GREP REGEX scripts for common BB-EDIT text-editing

Hi Everybody.. I'm a "newbie" to using Command-line... A few half-remembered DOS commands from 30 years ago, and the very handy "Sudo rm -R pathname" REMOVE command... I do a lot of "cleaning" of plain-text OCR text files. with assorted common line-break, punctuation and capitalization... (1 Reply)
Discussion started by: TheMacGuy
1 Replies

3. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

4. UNIX for Dummies Questions & Answers

Use of grep with multiple parameters in shell scripts

I am learning how to write shell scripts and have come across an issue. I'm trying to write a script that looks for a directory called public_html, and if it finds one, to print the number of lines that contain applet tags (containing '<applet') in all files that end in either .html or .htm that... (7 Replies)
Discussion started by: feverdream
7 Replies

5. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

6. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

7. Shell Programming and Scripting

Help with Script using rsh and scripts within scripts

Hi, I've written a script that runs on a Database server. It has to shutdown the Application server, do an Oracle Dump and then restart the Application server. Its been a long time since I wrote any shells scripts. Can you tell me if the scripts that I execute within my script will be executed... (3 Replies)
Discussion started by: brockwile1
3 Replies

8. UNIX for Dummies Questions & Answers

Profile scripts versus rc scripts....

what is the difference between login and profile scripts versus the rc scripts? (1 Reply)
Discussion started by: rookie22
1 Replies

9. Shell Programming and Scripting

multiple child scripts running in backgroud, how to use grep on the parent?

Hi I have a shell script A which calls another 10 shell scripts which run in background. How do i make the parent script wait for the child scripts complete, or in other words, i must be able to do a grep of parent script to find out if the child scripts are still running. My Code: ... (5 Replies)
Discussion started by: albertashish
5 Replies

10. Shell Programming and Scripting

shell scripts to grep dn in ldif file

Hi gurus out there, 1)I am using ksh, in solaris 10. 2)I have one ldif file, I need to output user DN with attributes=<some pattern> to a file. Example: dn: uid=joy,ou=People,o=abc.com,o=isp nswmExtendedUserPrefs: meAutoSign=true nswmExtendedUserPrefs: meSignature=Regards, Joy... (3 Replies)
Discussion started by: bulkbiz
3 Replies
Login or Register to Ask a Question