Visit Our UNIX and Linux User Community

How to print range of lines using sed when pattern has special character "["

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print range of lines using sed when pattern has special character "["
# 1  
Old 05-06-2010
How to print range of lines using sed when pattern has special character "["


My input has much more lines, but few of them are below

        pin(IDF[3]) {
                direction       :       input;
                drc_pinsigtype  :       signal;
        pin(SELDIV6) {
                direction       :       input;
                drc_pinsigtype  :       signal;

And i want output:
        pin(IDF[3]) {
                direction       :       input;
                drc_pinsigtype  :       signal;
        pin(SELDIV6) {

In my script:
set pinname = "IDF[3]"
sed -n "/$pinname/,/pin/p" <inputfile>

but above command is giving error because of the presence of special character "[" & "]".

Where i am doing mistake, please let me know.

Last edited by Scott; 05-06-2010 at 05:38 AM.. Reason: Code tags, please...
# 2  
Old 05-06-2010
Use \[ and \] instead.
# 3  
Old 05-06-2010
No, I cant use \[, \] as these values are stored in a variable in very early stages. Please give me another solution
# 4  
Old 05-06-2010
"[" and "]" are the part of regular expressions. You must have to escape their special meaning. one way is to use another (modified) variable.

see this thread for more details.

Previous Thread | Next Thread
Test Your Knowledge in Computers #557
Difficulty: Easy
The most expert of software developers never make mistakes.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove a word that ends with special character "!"

Hi all. I want to use sed to remove a word that ends with "!" in the first page of a file. The word I want to remove is: "DNA!". I have search for an answer and nothing of what I found helped me. ~faizlo (2 Replies)
Discussion started by: faizlo
2 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

Remove word after special character "/"

Hi There, I have one requirement to remove word after character "/". Input file is 2017-07-12|02|user1l|domain1/userl|0 2017-07-12|02|user2|domain1/user2|5 2017-07-12|02|user3|domain2/user3|0 2017-07-12|02|user4|domain1/user4|432 and require OP file is ... (2 Replies)
Discussion started by: anshu ranjan
2 Replies

4. Shell Programming and Scripting

sed random \n for "n" range of character occurrences

I'd like to put paragraph breaks \n\n randomly between 5 - 10 occurrences of the dot character (.), for an entire text file. How to do that? In other words, anywhere between every 5 -10 sentences, a new paragraph will generate. There are no other uses of the (.) except for sentence breaks in... (11 Replies)
Discussion started by: p1ne
11 Replies

5. Shell Programming and Scripting

Unable to identify the special characters beyond the range of "[\x80-\xFF]"

I want to filter out the special character whose ascii value doesn't fall within the range "" . Example:� or Ć. So in that case is there any defined range which will filter out this characters. I can filter those which falls withing "" . Need to filter those special chracter which doesn't... (14 Replies)
Discussion started by: Abhijit Sen
14 Replies

6. Shell Programming and Scripting

Sed print range of lines between line number and pattern

Hi, I have a file as below This is the line one This is the line two <\XMLTAG> This is the line three This is the line four <\XMLTAG> Output of the SED command need to be as below. This is the line one This is the line two <\XMLTAG> Please do the need to needful to... (4 Replies)
Discussion started by: RMN
4 Replies

7. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. UNIX for Dummies Questions & Answers

perl split funciton - special character "/"

HI, I have a directory structure. /abc/def/ghi/ I want to store it into array. So that if I do a pop function on that array I can easily go to previous directory. But how can i split and store it. @Directory = split(/\//,$DirectoryVarialbe) That doest works. Any other escape sequence... (5 Replies)
Discussion started by: deepakwins
5 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep ""|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep ""|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

Featured Tech Videos