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

What do you mean by it "didn't work"? Give us some information :wink:
You can match "a" and "A" with grep's -i parameter for case-insensitivity.

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.

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 :confused: Anybody any idea why?

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.

@view_lista = `cleartool lsview -short | egrep '^a'`;

i.e. put ^a in quotes ' '

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.

abdurrouf,

The below looks only for line starting with "a"
@view_lista = `cleartool lsview -short | egrep '^a'`;

since you want lines starting with both "a" or "A"
you may want to use this

@view_lista = `cleartool lsview -short | egrep ^'a|A'`;