Skip to main content
added 136 characters in body
Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

Assuming you want the first of the two identical blocks:

$ sed '/cell alatch {/,/^}/!d; /^}/q' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

The /cell alatch {/,/^}/ range is the range of lines that you want to get as output.

The sed expressions first deletes all lines not in this range, and then quits as soon as a } is found at the start of a line. The q instruction will cause sed to terminate after it outputs the current line, so the final } will get printed.

Executing the d instruction immediately skips to the next input line and branches back to the start of the editing script, so the q instruction has no way of executing unless it's in the range which does not cause d to execute.


With awk, achieving the same effect with code that should be reminiscent of the sed code above:

$ awk '/cell alatch {/,/^}/ { print; if ($0 ~ /^}/) exit }' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

Actually, this is closer to the sed command

sed -n '/cell alatch {/,/^}/{ p; /^}/q; }' file 

which does the same thing.

Assuming you want the first of the two identical blocks:

$ sed '/cell alatch {/,/^}/!d; /^}/q' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

The /cell alatch {/,/^}/ range is the range of lines that you want to get as output.

The sed expressions first deletes all lines not in this range, and then quits as soon as a } is found at the start of a line. The q instruction will cause sed to terminate after it outputs the current line, so the final } will get printed.

Executing the d instruction immediately skips to the next input line and branches back to the start of the editing script, so the q instruction has no way of executing unless it's in the range which does not cause d to execute.


With awk, achieving the same effect with code that should be reminiscent of the sed code above:

$ awk '/cell alatch {/,/^}/ { print; if ($0 ~ /^}/) exit }' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

Assuming you want the first of the two identical blocks:

$ sed '/cell alatch {/,/^}/!d; /^}/q' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

The /cell alatch {/,/^}/ range is the range of lines that you want to get as output.

The sed expressions first deletes all lines not in this range, and then quits as soon as a } is found at the start of a line. The q instruction will cause sed to terminate after it outputs the current line, so the final } will get printed.

Executing the d instruction immediately skips to the next input line and branches back to the start of the editing script, so the q instruction has no way of executing unless it's in the range which does not cause d to execute.


With awk, achieving the same effect with code that should be reminiscent of the sed code above:

$ awk '/cell alatch {/,/^}/ { print; if ($0 ~ /^}/) exit }' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

Actually, this is closer to the sed command

sed -n '/cell alatch {/,/^}/{ p; /^}/q; }' file 

which does the same thing.

added 319 characters in body
Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

Assuming you want the first of the two identical blocks:

$ sed '/cell alatch {/,/^}/!d; /^}/q' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

The /cell alatch {/,/^}/ range is the range of lines that you want to get as output.

The sed expressions first deletes all lines not in this range, and then quits as soon as a } is found at the start of a line. The q instruction will cause sed to terminate after it outputs the current line, so the final } will get printed.

Executing the d instruction immediately skips to the next input line and branches back to the start of the editing script, so the q instruction has no way of executing unless it's in the range which does not cause d to execute.


With awk, achieving the same effect with code that should be reminiscent of the sed code above:

$ awk '/cell alatch {/,/^}/ { print; if ($0 ~ /^}/) exit }' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

Assuming you want the first of the two identical blocks:

$ sed '/cell alatch {/,/^}/!d; /^}/q' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

The /cell alatch {/,/^}/ range is the range of lines that you want to get as output.

The sed expressions first deletes all lines not in this range, and then quits as soon as a } is found at the start of a line. The q instruction will cause sed to terminate after it outputs the current line, so the final } will get printed.

Executing the d instruction immediately skips to the next input line and branches back to the start of the editing script, so the q instruction has no way of executing unless it's in the range which does not cause d to execute.

Assuming you want the first of the two identical blocks:

$ sed '/cell alatch {/,/^}/!d; /^}/q' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

The /cell alatch {/,/^}/ range is the range of lines that you want to get as output.

The sed expressions first deletes all lines not in this range, and then quits as soon as a } is found at the start of a line. The q instruction will cause sed to terminate after it outputs the current line, so the final } will get printed.

Executing the d instruction immediately skips to the next input line and branches back to the start of the editing script, so the q instruction has no way of executing unless it's in the range which does not cause d to execute.


With awk, achieving the same effect with code that should be reminiscent of the sed code above:

$ awk '/cell alatch {/,/^}/ { print; if ($0 ~ /^}/) exit }' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 
added 53 characters in body
Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

Assuming you want the first of the two identical blocks:

$ sed '/cell alatch {/,/^}/!d; /^}/q' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

The /cell alatch {/,/^}/ range is the range of lines that you want to get as output.

The sed expressions first deletes all lines not in this range, and then quits as soon as a } is found at the start of a line. The q instruction will cause sed to terminate after it outputs the current line, so the final } will get printed.

Executing the d instruction immediately skips to the next input line and branches back to the start of the editing script, so the q instruction has no way of executing unless it's in the range which does not cause d to execute.

Assuming you want the first of the two identical blocks:

$ sed '/cell alatch {/,/^}/!d; /^}/q' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

The /cell alatch {/,/^}/ range is the range of lines that you want to get as output.

The sed expressions first deletes all lines not in this range, and then quits as soon as a } is found at the start of a line. The q instruction will cause sed to terminate after it outputs the current line, so the final } will get printed.

Executing the d instruction immediately skips to the next input line, so the q instruction has no way of executing unless it's in the range which does not cause d to execute.

Assuming you want the first of the two identical blocks:

$ sed '/cell alatch {/,/^}/!d; /^}/q' file cell alatch { pins on T { VSS VDDPI VDDP } pins on L { IN CT CB } pins on R { OUT } inputs { CB CT IN } outputs { OUT } } 

The /cell alatch {/,/^}/ range is the range of lines that you want to get as output.

The sed expressions first deletes all lines not in this range, and then quits as soon as a } is found at the start of a line. The q instruction will cause sed to terminate after it outputs the current line, so the final } will get printed.

Executing the d instruction immediately skips to the next input line and branches back to the start of the editing script, so the q instruction has no way of executing unless it's in the range which does not cause d to execute.

Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k
Loading