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 use UNIX C shell to process file?

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
replace with arabic text using sed unix shell

Hi, Now I have one file as following:

-- abcd efgh
-- mm gg
-- ddd
123456
abcdefgh
-- here there is some whitespace...
gggg
fffffff
(File end here)

**************************
I use the following UNIX C shell to exclude those line starting with '--'.

#!/bin/csh

foreach line (`cat file.txt`)
if ($line =~ "--")
echo $line
endif
end



The script always fail to work...

Can you help me??

Because for the "foreach" in CSHELL,
the list element is split using whitespace instead of "change line",
SO there is some strings like "abcd", "efgh" will be assigned to $line.

Any method to solve this problem?

Thanks a lot.
 

In such cases better you write perl script. csh has limited file
handling and regular expession capabilities.
 

Or use sed

if you dont have perl

sed uses ed syntax

/Bingo
 

Yes, I can use Perl, because in Perl,
it has the capability to process the line.

But I prefer to use UNIX C shell.

Because it is more familiar by other design engineer.

It seems less guys know how to understand perl.


Thanks a lot.

Added after 1 hours 43 minutes:

I tried to use _ to replace all the whitespace in the file; now it can work.

Thanks a lot.

Best Regards,
Tony Tao
 

hi tony_taoyh

Most verification engineers and validation engineers use Perl to deal with the files. This is the basic requirement.

Good Luck
 

Hi, Alex,

I do not think so.
Because many Engineers I know do not use Perl.

I just think VHDL and Verilog is necessary.

Perl is optional.

I just use Perl to ease my life in design and verification.

Thanks.

Best Regards,
Tony Tao
 

Hi tony_taoyh,

If you have interesting in this question, you may search the position information of verification and validation job from famous IC design companies, even IC design job.

Verilog/VHDL is necessary for design, but this is impossible to finish a complex design only with Verilog/VHDL. For verification, Perl, PLI, Assertion language, and so on are important.

Good Luck.
 

You can use sed for this job.
put this in sed command file
/^--/ {
d
}

invoke sed -f command.sed. this will remove all the lines starting with --
 

why don't you use grep -v "--" <filename> - this will give you all the lines other than those with a '--"

use '^--' if you don't want lines _starting_ with --


===
Bully
 

Hi, K12345,

Thanks a lot.

You advice is so good...

then I can try to use:
forech line ('grep -v -- filename.txt')

instead of:
foreach line ('cat filename.txt');

this is one good advice.

Thanks a lot.

Best Regards,
Tony Tao
 

Hi there,

As posted by many people, there are a lot of ways to get your work done, shell,
sed, awk, grep and perl. However, Perl is the best choice for this kind of tasks.

When you have to handle a big file, extract something interesting, or change and/or add something, Perl is No.1 candidate.

I have ever written a language parsor using Perl. It is really amazing tool.
I strongly recommand it.

Regards,
rprince006
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top