Search for string between specific lines of code in vi


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Search for string between specific lines of code in vi
# 1  
Old 07-14-2009
Search for string between specific lines of code in vi

Hi,
I am on an AIX Unix box and I am trying to search for a string in between specified lines of code when I vi a file. I can use the '/string' to search for the string through out the file, but can we only search in between specific lines.

I can use the below sed command to search for the string between line numbers 1594 and 1857, but I was curious to know if there is any other way I could do the same when I vi the file ?
Code:
sed -n "1594,1857p" name.ksh | grep string | more

Looking forward to learn new stuff from all of you. Please let me know if you have any questions.

Thanks,
Coolavi

Last edited by Yogesh Sawant; 07-15-2009 at 02:57 AM.. Reason: added code tags
# 2  
Old 07-14-2009
I think the best you may be able to do is something like:
Code:
:1594;/string/

But that won't stop at 1857

Last edited by Yogesh Sawant; 07-15-2009 at 02:57 AM.. Reason: added code tags
# 3  
Old 07-15-2009
in command mode:
Code:
/\%>1549l\%<1857lstring

then, press n to repeat this search
# 4  
Old 07-15-2009
Thanks for your response cjcox and Yogesh.

Yogesh, I tried using code /\%>1549l\%<1857lstring in vi command mode and I am getting the following error:

E71: Invalid character after \%


Any suggestions ?

Thanks,
coolavi
# 5  
Old 07-15-2009
Looks like you have a | for the 1 in his example.
# 6  
Old 07-16-2009
My bad!

Yogesh, it works like a charm. I mis-interpreted the alphabet 'l' (lower case L as in long) as 1.
nj78, thanks for pointing out the mistake.


Also, can one of you guys interpret this, as to how you were able to work it out? I think learning and understanding the concept is the more important than just getting the result.

Thanks,
coolavi
# 7  
Old 07-16-2009
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. Shell Programming and Scripting

Search and replace specific positions of specific lines

Hi, I have a file with hundreds of lines. I want to search for particular lines starting with 4000, search and replace the 137-139 position characters; which will be '000', with '036'. Can all of this be done without opening a temp file and then moving that temp file to the original file name. ... (7 Replies)
Discussion started by: dsid
7 Replies

3. UNIX for Dummies Questions & Answers

Search specific string logfile specific date range

Hi, I have logfile like this.. === 2014-02-09 15:46:59,936 INFO RequestContext - URL: '/eyisp/sc/skins/EY/images/pickers/comboBoxPicker_Over.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko': Unsupported with Accept-Encoding header === 2015-02-09... (8 Replies)
Discussion started by: kishk
8 Replies

4. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

5. Shell Programming and Scripting

Printing all lines before a specific string and a custom message 2 lines after

Hello all, I need to print all the lines before a specific string and print a custom message 2 lines after that. So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message. My code thus far is:... (4 Replies)
Discussion started by: SEinT
4 Replies

6. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

7. Shell Programming and Scripting

substitute a string on a specific position for specific lines

I woud like to substitue a string on a specific position for specific lines I've got a file and I would like to change a specific string from "TOCHANGE" to "ABCABCAB" For every line (except 1,2, 3 and the last one) , I need to check between the 9th and the 16th digits. For the 3rd line, I... (7 Replies)
Discussion started by: BSF
7 Replies

8. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

9. Shell Programming and Scripting

Search a specific string

Hi, I have following requirement. Pls suggest. To search a string in a file which is combination of character and number(always 9 digit, but numeric). if found then caputure the exit return code as 0 else 1 , if 0 then next job can be triggerd. If exit code is 1, should return a failure... (10 Replies)
Discussion started by: zooby
10 Replies

10. Shell Programming and Scripting

Print lines with search string at specific position

Hi Folks, I have a file with all fields defined by byte position, but any field can be empty so I cannot print lines based on a search of specific columns. I need to print all lines of this file where the string of two characters at byte position 100-101 contains the number 27. Any ideas? ... (4 Replies)
Discussion started by: HealthyGuy
4 Replies
Login or Register to Ask a Question