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 write some common lines into multiple files in a directory ?

Status
Not open for further replies.

hcu

Advanced Member level 4
Joined
Feb 28, 2017
Messages
101
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
874
how to write some common lines into a multiple files in a directory ?

Hello,

I have about 110 source files, each file vary in size and vary in number of lines inside.

for some reason, i want to write " some two Lines " exactly at the starting of each file content.

and a "one more line" exactly at the end of each file.

i.e the first two lines for every file should be
line 1 // pragma protect
line 2 //pragma protect begin

<file content>

last line //pragma protect end.

I want to automate this, plz somebody help me.

regards,
 

Re: how to write some common lines into a multiple files in a directory ?

Hi,

Linux:
cat file_header file_source file_footer > file_target

DOS:
copy /b file_header + file_source + file_footer file_target

Klaus
 
  • Like
Reactions: hcu

    hcu

    Points: 2
    Helpful Answer Positive Rating
Re: how to write some common lines into a multiple files in a directory ?

Hi,

Linux:
cat file_header file_source file_footer > file_target


Klaus

I am in linux,
i
i am getting
cat: file_header file: no such file or directory
cat: file_footer file: no such file or directory

I know , i am wrong , i am new to all these. plz breif

- - - Updated - - -

thank you, It helped me. No issues
 

Re: how to write some common lines into a multiple files in a directory ?

Hi,

One thing is, i want to keep my file name (i.e target file) name should be same as my original file name.
here the problem is , the data in the file is lost.

so, to avoid that

cat file_footer my_design.v file_header > ./folder/mydesign.v .

my questions are :
1.Is there anything better/efficiently i can do here otherthan above ?
2. as i said , i have 100's of files, 100 cat command lines are to be written . Any effiently way of doing this ??

thans in advance
 

Re: how to write some common lines into a multiple files in a directory ?

Hi,

file_header is the file that contains:
*****
// pragma protect
//pragma protect begin
*****



file_footer is the file that contains:
*****
//pragma protect end
*****



File_source is your source file

File_target is your target file.

Klaus

- - - Updated - - -

Hi,

if you want to do this with a batch or script .... and keep the file name ... than how can the batch/script know which file is modified and which one not?

Maybe use different filenames, different directories, or you need a tiny database/list where you store all the filenames, and a flag that shows if it is modified already or not.

Klaus
 

Re: how to write some common lines into a multiple files in a directory ?

HI,
I found a way of adding some lines to 100's of files at a time in a single click.

Code:
for f in ./hw/*.v
do
cat file_header $f file_footer > ./test/$f
done

1. to preserve the same file name. i written files to a folder "test"
2. to get my job done. the test folder must have a empty "hw" folder inside.

If you have any efficinet thoughts on it, share the idea.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top