How do i select all contents between two numbers?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do i select all contents between two numbers?
# 1  
Old 03-06-2012
How do i select all contents between two numbers?

I want to select contents between two numbers say 1. and 2. from an output file which has many numbers but only the these two ending with a dot(.) eg 1. 2 . 32. etc I was looking to select with the use of a counter then modify the selected contents and put it in an output file where again the output file seems to overwrite. The external file contains many spaces and new lines in the contents. I am newbie in scripting. Sorry for the long post.

Code:
"freedom 
hey begin Majnu 
Market M.G.Street 


Ghatkopar (W)
end
Mumbai 400086 India"

This would be the text in an external text file. I am looking to select every thing between 'begin' and 'end' then choose text based on match strings like street in this case and add into a filed named streets.

I have used
Code:
echo | sed -e '/begin/,/end/p' /path/to/file.text | more

to select text between begin and end


Code:
thisString=$inputline
searchString=" Street"

case $thisString in

*"$searchString"*) echo "Street found"

to find the letter Street.

Last edited by Corona688; 03-06-2012 at 02:13 PM.. Reason: Please use code tags for data and code samples
# 2  
Old 03-06-2012
I'm confused by your request, since I don't see anything like what you want to match (a number, followed by .) in your input text.
# 3  
Old 03-07-2012
I am so sorry. I will try to explain again. I am looking to select contents between two consecutive serial numbers from an external text file and search words between them ( eg street) and output it in a text file (eg street names).

eg:
1. blah blah. blah something.
some street, again some blah blah.
2. blah blah. blah something.
blah 589, some other street, again some blah blah.

Output in streetnames.text
some street
some other street... etc
# 4  
Old 03-07-2012
Something like this..?
Code:
[mkt@michael]$ sed -n '/begin/,/end/{
> /Street/p
> }' inputfile > streetnames.txt
[mkt@michael]$ cat streetnames.txt
Market M.G.Street
[mkt@michael]$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How Select numbers from a line of text, and remove leading spaces?

I have a text file with a line of text that contains numbers and text formatted into groups. I need to extract the number that can be either 1,2 or 3 digits long. Then write it to a variable, but i need to remove any leading spaces in the number first. I can get the numbers out but how to remove... (12 Replies)
Discussion started by: kcpoole
12 Replies

2. Shell Programming and Scripting

Select only line numbers using grep

Hai, I want to select only line numbers into a file if some pattern matches. I have written my script like below but its not working. #!/bin/sh file='/home/testfile1' filesearch='/home/test00' while read line do search=`echo $line |cut -c 1-24` echo $search echo `grep -n ""... (3 Replies)
Discussion started by: Subbu123
3 Replies

3. Shell Programming and Scripting

Select command with variable options having spaces or null contents

Hi, I'm having an issue trying to produce a hierarchical directory menu that has either any directories listed in a specific directory as options or options with spaces in the option content or null content. So the menu function gets passed a base directory, it then lists any .sh scripts in... (6 Replies)
Discussion started by: andyatit
6 Replies

4. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

5. Shell Programming and Scripting

using sed command to display contents where line numbers are stored in variables

if i want to display the contents of a file between say line number 3 and 10 then i use the following command sed -n '3,10p' filename if this 3 was contained in x and 10 was contained in y then how wud this command modified? sed -n '$x,$yp' filename does not work..please advise (2 Replies)
Discussion started by: arindamlive
2 Replies

6. Shell Programming and Scripting

Select the exact matching contents using grep

Hi everyone I've two files.. The contents of file1 are as shown below 4 5 12 13 36 37 45 46 47 The contents of file2 are as shown below 21 hello 13 world (5 Replies)
Discussion started by: abk07
5 Replies

7. Shell Programming and Scripting

finding common numbers (contents) across 2 or 3 files

I have 3 files which are tab delimited and have numbers in it. file 1 1 2 3 4 5 6 7 File 2 3 5 7 8 File 3 1 (4 Replies)
Discussion started by: Lucky Ali
4 Replies

8. Shell Programming and Scripting

select contents between two delimiters (not working if newline in encountered)

Hi, I am facing difficulties in selecting the contents between two delimiters when there is a new line occurs.. Eg: >more sample.txt abcd -- this is the first line % efgh-- this is the second line and not able to print % ijkl -- this is the 3rd line % when i search for abcd and... (8 Replies)
Discussion started by: Balaji PK
8 Replies

9. UNIX for Advanced & Expert Users

How to select only those file names whose name contains only numbers

Hi Guru's, Before writing to this forum I have searched extensively on this forum about my problem. I have to write a shell script which takes out only those file names from the given directory which contains only numbers. For example, In the given directory these files are present: ... (4 Replies)
Discussion started by: spranm
4 Replies

10. UNIX for Dummies Questions & Answers

How to select only those file names whose name contains only numbers.

Hi Guru's, Before writing to this forum I have searched extensively on this forum about my problem. I have to write a shell script which takes out only those file names from the given directory which contains only numbers. For example, In the given directory these files are present: ... (0 Replies)
Discussion started by: spranm
0 Replies
Login or Register to Ask a Question