SED / Line / (Need to get data from searched line from specific char to char)

SED / Line / (Need to get data from searched line from specific char to char)

Post by Tomi Koivist » Tue, 12 Oct 1999 04:00:00



Hello !

I need to search line from text file which contains specific text in start
of it.
Then I need to get text from specific place in a line. Like craracters from
10 to 20.

File looks like this:
A             5308,99
B             -2342,23
*** Total -34505,40
* D           2344,30

I need to get that Total number.

So the guestion is what utility should I use and how to do it ?

I'm using SED 2.05 in NT. I also don't find newer SED for NT.

So I need to do it in NT !

I know this is UNIX group, but NT-users don't know these kind of things....

Thanks !
Tomi Koivisto
Finland

 
 
 

SED / Line / (Need to get data from searched line from specific char to char)

Post by Ken Pizzi » Tue, 12 Oct 1999 04:00:00



>I need to search line from text file which contains specific text in start
>of it.
>Then I need to get text from specific place in a line. Like craracters from
>10 to 20.

>File looks like this:
>A             5308,99
>B             -2342,23
>*** Total -34505,40
>* D           2344,30

>I need to get that Total number.

sed -n 's/^\*\*\* Total //p'

Quote:>I'm using SED 2.05 in NT. I also don't find newer SED for NT.

>So I need to do it in NT !

You might need to change the 's to "s then; I seem to recall
that MS command interpreters don't use 's for parameter quoting.

                --Ken Pizzini

 
 
 

SED / Line / (Need to get data from searched line from specific char to char)

Post by Richard J. Botti » Wed, 13 Oct 1999 04:00:00


Ken's reply is a good solution to specific
problem:
Quote:>>File looks like this:
>>A             5308,99
>>B             -2342,23
>>*** Total -34505,40
>>* D           2344,30

>>I need to get that Total number.

Ken's reply including  cahnging ' to ":

Quote:>sed -n "s/^\*\*\* Total //p"

In general to find lines starting with X
and selecting a string starting with first Y
and going to last Z try something like:
sed -n "s/^X.*\(Y.*Z\)/\1/p
or if you want a piece after the first Y
and finishing just before the last Z:
sed -n "s/^X.*Y\(.*\)Z/\1/p

Hope these are correct and this helps.

dick

rbotting at CSUSB edu
Computer Scientist, Sys Admin, Consultant, Researcher, and Reviewer
http://www.csci.csusb.edu/dick

 
 
 

SED / Line / (Need to get data from searched line from specific char to char)

Post by David Kenned » Fri, 15 Oct 1999 04:00:00



> Then I need to get text from specific place in a line. Like craracters from
> 10 to 20.
> I need to get that Total number.
> So the guestion is what utility should I use and how to do it ?

I recall using Unix utilities under NT so this simple solution
might be of some use to you.

grep Total file | cut -c 10-20

does exactly what you asked.

The easy sed solution depends on your exact line format but
is going to be something like:
s/^\*\*\* Total //p    
--

Northern Ireland Telecommunications | ESN:   6 751 2678
  Engineering Centre (NITEC),       | Phone: 01232 362678
Nortel Networks                     | Fax:   01232 363170