Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to match the first two characters in UNIX C shell?

Status
Not open for further replies.

tony_taoyh

Full Member level 2
Joined
Oct 20, 2004
Messages
131
Helped
6
Reputation
12
Reaction score
3
Trophy points
1,298
Activity points
1,785
During my setup of simulation environment,
I want to use UNIX C shell.

Now I have one variable:
set aa = "-- abcd efgh"

Then how to use C shell to decide the variable is strating with "--",
thanks a lot.
 

Here is an example script


Code:
#!/bin/csh -f
set aa = "-- abcd efgh" ;
echo $aa
if( "$aa" =~ --*) then
  echo "Match found";
else
  echo "No match";
endif

Hope this helps
 

Yes, it can work...

The * in:
if ($line =~ --*) is important.

Thanks a lot.

Best Regards,
Tony
 

Try to use perl, it is much more powerful for this kind of tasks.

Let me give you an example:

#!/bin/perl -w

use strict ;

my $filename = "yourfile";
my $outfile = "myoutputfile" ;

open(FH, "$filename") or die "cannot open $filename";
open(FHO, "$outfile") or die "cannot open $outfile";

while ( <FH> ) {

## Matching any patterns here!!

if ( /^--/ ) {
print "Pattern Matched.\n" ;

print FHO ""£%$£%" ; ## Put anything in your output file.
}
else {
print "Pattern did'nt match\n" ;
}
}

close FH ;

exit 0;

Regards,
rprince006
 

Yes, turn to perl please.
Csh is not fit for programming.

Search " Csh harmful programming" in google.You will get the answer why csh is not fit for progarmming
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top