Sponsored Content
Top Forums Shell Programming and Scripting shell script for extracting out the shortest substring from the given starting and en Post 302141519 by radoulov on Friday 19th of October 2007 11:37:48 AM
Old 10-19-2007
With GNU Awk:
Code:
awk 'NF>1&&$0=(FS $NF RT){
	if(length<min){
		min=length;rec=$0}
	}END{
print rec
}' FS="$start" RS="$end" min=9^9 filename

Code:
$ cat file
abcdpqracdpqaserd
$ start=a
$ end=d
$ awk 'NF>1&&$0=(FS $NF RT){
if(length<min){
min=length;rec=$0}
}END{
print rec
}' FS="$start" RS="$end" min=9^9 file
acd
$ start=a
$ end=p
$ awk 'NF>1&&$0=(FS $NF RT){
if(length<min){
min=length;rec=$0}
}END{
print rec
}' FS="$start" RS="$end" min=9^9 file
acdp
$ start=a
$ end=r
$ awk 'NF>1&&$0=(FS $NF RT){
if(length<min){
min=length;rec=$0}
}END{
print rec
}' FS="$start" RS="$end" min=9^9 file
aser

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substring in C shell script?

i am a new user of C-shell script. I want to know can i create a substring in a string. That means when i got a variable $input = "it is number 2" I want to get the "2" to be another variable. Can i do that in C-shell and how to ? Thank you so much dinodash (0 Replies)
Discussion started by: dinodash
0 Replies

2. UNIX for Dummies Questions & Answers

problem extracting substring in korn shell

hi all, I have read similiar topics in this board, but i didn' t find the posting which is the same with the problem i face.. I try to extract string from the end. i try to do this: num=abcdefghij num2=${num:-5} echo $num2 #this should print the last 5 characters (fghij) but it doesn;t... (3 Replies)
Discussion started by: nashrul
3 Replies

3. UNIX for Dummies Questions & Answers

Substring in Shell Script

Hi I'm new to Shell scripting. Someone please help me in extracting a portion of string from a file. Eg: I got a file like, Readme.txt and has the following name value pairs input1 : /homes/input1/ input2 : /homes/input2/ ... ... When I give the parameter input1, the value... (3 Replies)
Discussion started by: smartbuddy
3 Replies

4. Shell Programming and Scripting

help for shell script of finding shortest substring from given string by user

please give me proper solution for finding a shortest substring from given string if string itself and first char and last char of that substr are also given by user if S="dpoaoqooroo" and FC="o" and LC="o",then shortest substr is "oo" and rest of the string is "dpoaoqroo" i have code but it is... (1 Reply)
Discussion started by: pankajd
1 Replies

5. Shell Programming and Scripting

Extracting a substring starting from last occurance of a string/character

Hi All, This is Ram. I'm new to this forum & new to shell scripts as well. I've a requirement in which I want to extract a substring from a given string based on last occurance of a character. for eg. I have a string of a file name with absolute path like... (2 Replies)
Discussion started by: krramkumar
2 Replies

6. Shell Programming and Scripting

Substring in shell script

I need a help in getting substring of each line in input file. I am writing a script that will read a file from a directory on daily basis, I mean everyday a new file will be stored in this directory, it will replace old file. I have to read contents of this file, the contents will be as... (5 Replies)
Discussion started by: jyotib
5 Replies

7. Shell Programming and Scripting

using substring in shell script

This is the data I am having in a file Just for sample I have given 3 records. The file which I am having consists of n number of records. ABC123 10 01/02/2008 2008-01-03-00.00.00.000000 DYUU 22 02/03/2008 2008-01-04-00.00.00.000000 RF33 88 03/05/2008 2008-01-05-00.00.00.000000 ... (24 Replies)
Discussion started by: kmanivan82
24 Replies

8. Shell Programming and Scripting

extracting substring from a file name

hi i need to name a file with a substring of a another file name. i.e. if the old filename is abc.txt , the new filename should be abc_1.txt i should get the substring of the file name and then name the new one please let me know how to do it (4 Replies)
Discussion started by: adityamahi
4 Replies

9. Shell Programming and Scripting

Extracting substring from string

Hi awk and sed gurus, Please help me in the following. I have the following entries in the file ABCDErules AbHDPrules ABCrules -- -- and other entries in the file. Now, I want to extract from the file that contain entries for *rules and process it separately. How can i do it... (6 Replies)
Discussion started by: sdosanjh
6 Replies

10. Shell Programming and Scripting

Extracting substring

Hi, I have string in variable like '/u/dolfin/in/DOLFIN.PRL_100.OIB.TLU.001.D20110520.T040010' and i want to conevrt this string into only "DOLFIN.PRL_100.OIB.TLU.001.D20110520.T040010" (i.e file name). Is there any command to extracting string in some part ?(rather than whole path)? ... (5 Replies)
Discussion started by: shyamu544
5 Replies
mlib_ImageExtremaLocations(3MLIB)			    mediaLib Library Functions				 mlib_ImageExtremaLocations(3MLIB)

NAME
mlib_ImageExtremaLocations, mlib_ImageExtremaLocations_Fp - image extrema and their locations SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_ImageExtremaLocations( mlib_s32 *min, mlib_s32 *max, const mlib_image *img, mlib_s32 xStart, mlib_s32 yStart, mlib_s32 xPeriod, mlib_s32 yPeriod, mlib_s32 saveLocations, mlib_s32 maxRuns, mlib_s32 *minCounts, mlib_s32 *maxCounts, mlib_s32 **minLocations, mlib_s32 **maxLocations, mlib_s32 len); mlib_status mlib_ImageExtremaLocations_Fp( mlib_d64 *min, mlib_d64 *max, const mlib_image *img, mlib_s32 xStart, mlib_s32 yStart, mlib_s32 xPeriod, mlib_s32 yPeriod, mlib_s32 saveLocations, mlib_s32 maxRuns, mlib_s32 *minCounts, mlib_s32 *maxCounts, mlib_s32 **minLocations, mlib_s32 **maxLocations, mlib_s32 len); DESCRIPTION
Each of the functions finds the image-wise minimum and maximum pixel values for each channel, and optionally, their locations. Each of the functions scans an image, finds the minimum and maximum pixel values for each channel, and finds the locations of those pixels with the minimum or maximum values. The user provides initial minimum/maximum values through the arguments min and max. This function will update them based on findings. The set of pixels scanned may furthermore be reduced by specifying xPeriod and yPeriod parameters that specify the sampling rate along each axis. The set of pixels to be scanned may be obtained from the following equation: x = xStart + p*xPeriod; 0 <= p < (w - xStart)/xPeriod y = yStart + q*yPeriod; 0 <= q < (h - yStart)/yPeriod The locations of the minimum/maximum, if asked, are recorded in a format of run-length coding. Each run-length code, or simply called a run, has a format of (xStart, yStart, length). Here length is defined on the low-resolution image (with downsampling factors of 1/xPeriod, 1/yPeriod) and does not cross rows. So the run-length code (xStart, yStart, length) means that the pixels at (xStart, yStart), (xStart + xPeriod, yStart), ..., (xStart + (length - 1)*xPeriod, yStart) of the original image have a value of the minimum/maximum. The buffers for minLocations and maxLocations are organized in the following format for each channel i: minLocations[i][0] = xStart0; // the 1st run minLocations[i][1] = yStart0; minLocations[i][2] = length0; minLocations[i][3] = xStart1; // the 2nd run minLocations[i][4] = yStart1; minLocations[i][5] = length1; ...... // more runs minLocations[i][len-1] = ...; It is the user's responsibility to allocate enough memory for the buffers for minLocations and maxLocations. This function may return MLIB_OUTOFRANGE, if any of the buffers is not big enough. PARAMETERS
The function takes the following arguments: min Pointer to the minimum values. max Pointer to the maximum values. img Pointer to the input image. xStart Initial X sample coordinate. yStart Initial Y sample coordinate. xPeriod X sampling rate. xPeriod >= 1. yPeriod Y sampling rate. yPeriod >= 1. saveLocations If true (i.e., saveLocations != 0), find the extrema locations; otherwise only find the extrema. maxRuns Number of runs of the minimum/maximum the caller expects for each channel. maxRuns >= 1. If it is MLIB_S32_MAX, all the minimum/maximum locations should be recorded. minCounts Pointer to the numbers of runs of the minimum recorded in minLocations. maxCounts Pointer to the numbers of runs of the maximum recorded in maxLocations. minLocations Pointer to the minimum locations in a format of run-length coding. maxLocations Pointer to the maximum locations in a format of run-length coding. len Length of the buffers for the minimum/maximum locations in each channel. RETURN VALUES
The function returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_ImageExtrema2(3MLIB), mlib_ImageMaximum(3MLIB), mlib_ImageMaximum_Fp(3MLIB), mlib_ImageMinimum(3MLIB), mlib_ImageMinimum_Fp(3MLIB), attributes(5) SunOS 5.10 10 Nov 2004 mlib_ImageExtremaLocations(3MLIB)
All times are GMT -4. The time now is 02:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy