Visit Our UNIX and Linux User Community


copy the contents between two keywords to a new file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copy the contents between two keywords to a new file.
# 1  
Old 10-19-2009
Network copy the contents between two keywords to a new file.

Hi All,

I want to edit my gate level netlists by searching for the content between two patterns

eg:

ff1 \test/a0 ( .CLK(\test/ClkInt0_acb_00x1 ),.D(\test/Rakicc ), .QB(\test/X [1]), .VDD(1'b1), .VSS(1'b0));
ff1 \test/a1 ( .CLK(\test/medis0_acb_00x1 ),.D(\test/hedwc ), .QB(\test/X [1]), .VDD(1'b1), .VSS(1'b0));
ff1 \test/a2 ( .CLK(\test/tergus_acb_00x1 ),.D(\test/Ddec ), .QB(\test/X [1]), .VDD(1'b1), .VSS(1'b0));
.....
.....

i need to grep the contents after ".CLK(" and before "),.D" and copy it to a new file.

Kindly help me with this.

Thanks a bunch
naveen
# 2  
Old 10-19-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.
  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote

Code:
sed 's/.*CLK(\(.*\) ),\.D.*/\1/' file

# 3  
Old 10-19-2009
Data part two of the problem i Have

thanks a lot danmero
i am new to shell scripting. Kindly help me with this if possible.

now that i have my list I need to replace them as follows

Code:
inv in_0 (.A(\test/ClkInt0_acb_00x1 ),.VDD(VDD),.VSS(VSS),.Z(i_0)); 
nand nd2_0 (.A(i_0), .B(VDD),.VDD(VDD),.VSS(VSS),.Z(nd_0));
ff1 \test/a0  ( .CLK(nd_0),.D(\test/Rakicc ), .QB(\test/X [1]), .VDD(1'b1), .VSS(1'b0), .A(tmp_0), .B(tmp_1) ); 

inv in_1 (.A(\test/medis0_acb_00x1 ),.VDD(VDD),.VSS(VSS),.Z(i_1)); 
nand nd2_1 (.A(i_1), .B(VDD),.VDD(VDD),.VSS(VSS),.Z(nd_1));
ff1 \test/a1  ( .CLK(nd_1)),.D(\test/hedwc ), .QB(\test/X [1]), .VDD(1'b1), .VSS(1'b0),.A(tmp_1), .B(tmp_2) );

nv in_2 (.A(\test/tergus_acb_00x1 ),.VDD(VDD),.VSS(VSS),.Z(i_2)); 
nand nd2_2 (.A(i_2), .B(VDD),.VDD(VDD),.VSS(VSS),.Z(nd_2));
ff1 \test/a2  ( .CLK(nd_2)),.D(\test/Ddec ), .QB(\test/X [1]), .VDD(1'b1), .VSS(1'b0),.A(tmp_2), .B(tmp_3) ); 
......
.......

I am using a lengthy workaround. i Initially generate a list using

Code:
#!/bin/bash
i=$1
while [ $i -lt $2 ]; do
j=$(($i+1))
echo "nv in_$i (.A(),.VDD(VDD),.VSS(VSS),.Z(i_$i)); 
 nand nd2_$i (.A(i_$i), .B(VDD),.VDD(VDD),.VSS(VSS),.Z(nd_$i));
(.CLK(nd_$i)),.D(), .QB(), .VDD(1'b1), .VSS(1'b0),.A(tmp_$i), .B(tmp_$j) ); "  >> temp_list.v
i=$(($i+1))
done

and then i manually replace other data. Could anyone help me with an easier workaround please?

Thanks again
Naveen


# 4  
Old 10-19-2009
bash
Code:
while read -r line
do
    case $line in 
        *CLK\(* ) 
            line=${line#*CLK\(}
            line=${line%.D(*}
            echo $line
            ;;
    esac    
done < "file"

# 5  
Old 10-20-2009
Hi All,
Could someone help me with the issue I have posted..

Thanks a lot
# 6  
Old 10-20-2009
Don't bump your question and try to explain what's the relationship between your first and second post.
# 7  
Old 10-21-2009
Hello....
Can someone out there help me with some shell scripting for the problem posted above????


Thanks a lot..
Naveen

Previous Thread | Next Thread
Test Your Knowledge in Computers #811
Difficulty: Easy
RGBA stands for red green blue alpha.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy last 30 minutes' contents from a log file

Hi Guys, I am writing a bash script to capture the last 30 minutes's contents from log file to a new file. This job is a scheduled job and will run every 30 minutes. The log file is db2diag.log in DB2. I am having difficulties copying the last 30 minutes's contents. Can someone please help me.... (4 Replies)
Discussion started by: naveed
4 Replies

2. UNIX for Dummies Questions & Answers

Copy Lines between Keywords & paste them to another file

hi, I have Multiple files with the following data : File1 100414 DR1 END XXXXX Test1 Test2 Test3 Test4 Test5 Test6 END 100514 DR2 END XXXXX Test7 Test8 Test9 Test10 Test11 Test12 END 100614 DR3 (5 Replies)
Discussion started by: newageBATMAN
5 Replies

3. Shell Programming and Scripting

Copy contents of one file to another

I need to write a script (in bash) that copies the content of the first file in each folder of a directory to the second file in the same folder. I tried this and it didn't work - it just came back with errors and I'm not sure how to fix it. Help is very much appreciated! for mpdir in... (4 Replies)
Discussion started by: LeftoverStew
4 Replies

4. Shell Programming and Scripting

Need Script to copy the contents of two files into one file

Hi i need Script to copy the contents of two files into one file i have 2 fil X1.txt / X2.txt i need script to copy the contents of X1 and X2 In AllXfile X1.txt File X1 X2.txt File X2 AllXfile.txt File X1 File X2 (2 Replies)
Discussion started by: azzeddine2005
2 Replies

5. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

6. Shell Programming and Scripting

Need help to copy contents of a file

Hi, I am stuck up with a problem of copying the contents of a directory where one of the folder name is changed daily. Problem: I have the folder structure as: RefWorlds2/LINGCC4_X64/odsdev/odessy/UTI/621GA_build_xxx/.../.. In the above path the build number (xxx) will be changed... (3 Replies)
Discussion started by: SathaKarni
3 Replies

7. UNIX for Dummies Questions & Answers

Copy entire contents of file to clipboard

Hi, I am trying to figure out how to copy the contents of a file to the clipboard, then paste into a command. i.e copy contents of file /path/filename.txt to <command> <paste text> Hope that makes sense. Basically tryting to copy the text for use in a command without having to open the... (8 Replies)
Discussion started by: JCA70
8 Replies

8. Shell Programming and Scripting

Copy contents of a directory only if a file exists

I'm looking to write a script that will check the contents of a directory, and if any files exist in that directory copy them to a temporary folder. The target files are only resident for a few seconds, so I think the script needs to be running constantly. Any pointers would be really... (3 Replies)
Discussion started by: danceofillusion
3 Replies

9. Shell Programming and Scripting

Automatic Copy of File Contents to Clipboard

Could someone show me how to copy the contents of a file to the clipboard automatically without manually selecting its contents? I just want to press the "Paste Key" to show the results. I wish to use this in a ksh script. I'm using Solaris. Thanks! (5 Replies)
Discussion started by: ilak1008
5 Replies

10. Shell Programming and Scripting

Copy selected contents from file

I want to capture contents of a file between 2 strings into another file for eg all lines in between the keywords "start log" and "end log" should be copied into another file (4 Replies)
Discussion started by: misenkiser
4 Replies

Featured Tech Videos