+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Member level 5
    Points: 818, Level: 6

    Join Date
    Feb 2017
    Posts
    93
    Helped
    0 / 0
    Points
    818
    Level
    6

    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,

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 77,026, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,607
    Helped
    3556 / 3556
    Points
    77,026
    Level
    67

    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


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  3. #3
    Member level 5
    Points: 818, Level: 6

    Join Date
    Feb 2017
    Posts
    93
    Helped
    0 / 0
    Points
    818
    Level
    6

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

    Quote Originally Posted by KlausST View Post
    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



    •   AltAdvertisement

        
       

  4. #4
    Member level 5
    Points: 818, Level: 6

    Join Date
    Feb 2017
    Posts
    93
    Helped
    0 / 0
    Points
    818
    Level
    6

    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



  5. #5
    Super Moderator
    Points: 77,026, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,607
    Helped
    3556 / 3556
    Points
    77,026
    Level
    67

    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



    •   AltAdvertisement

        
       

  6. #6
    Member level 5
    Points: 818, Level: 6

    Join Date
    Feb 2017
    Posts
    93
    Helped
    0 / 0
    Points
    818
    Level
    6

    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.



--[[ ]]--