Sponsored Content
Top Forums Shell Programming and Scripting extracting a number from a string Post 302203061 by joeyg on Friday 6th of June 2008 11:33:58 AM
Old 06-06-2008
Tools Couple of things to try...

Take a look below. I think it shows ways of getting to before the 'x' and the 2 digits after the 'x'. There may be more elegant solutions, but this one appears to work.

Code:
> echo $val1
ts1n65ulpa4096x16m16_130a_ss1p08v125c
> echo $val1 | cut -c11-
4096x16m16_130a_ss1p08v125c
> echo $val1 | cut -c11- | cut -d"x" -f1
4096
> echo $val1 | cut -c11- | cut -d"x" -f2
16m16_130a_ss1p08v125c
> echo $val1 | cut -c11- | cut -d"x" -f2 | cut -c1-2
16

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting 10 digit number from txt files

Hi, Was wondering if you could give me an example of extracting a 10 digit number from 5 txt files using a regular expression (the number is always different ) and storing the numbers in variables Thanks C19 (9 Replies)
Discussion started by: c19h28O2
9 Replies

2. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

3. Shell Programming and Scripting

Extracting a Number from Passage

( Database Connection Information Database server = DB2/AIX6000 8.1 SQL authorization ID = LAKNAR Local database alias = SAMPLE ROWSAFFECTED ------------ 1 1 record(s) selected. DB20000I The SQL command completed successfully. DB20000I The TERMINATE... (1 Reply)
Discussion started by: laknar
1 Replies

4. Shell Programming and Scripting

Extracting N lines match number X of a pattern

Hi All, as the title says I need to extract N lines after match number X of a pattern. e.g. 111 xxx xxx 111 yyy yyy 111 www www 111 zzz zzz I would like to extract the two lines after the second 111 occurrence. I tried with grep but I didn't find any options to do that. Any... (11 Replies)
Discussion started by: f_o_555
11 Replies

5. Shell Programming and Scripting

changing number in bash (number is in form of string)

I have a txt file as database. when i run my program what it does is it ask me for 3 name and stored in the file as name1:name2:name3:1 when u enter 3 name it add those in file as above format and add 1 at the end. I what i want is if i enter same names again it changes that 1 to 2 and so... (3 Replies)
Discussion started by: Learnerabc
3 Replies

6. Shell Programming and Scripting

Extracting a certain number with grep command

Hello Friends, when I type grep '275' myfile.txt it gives me all the lines including 275 but it also gives others such as 0.8827588 or 1127507. I only want the lines including 275. How can I extract only 275 without other numbers including 275. thanks (2 Replies)
Discussion started by: rpf
2 Replies

7. Shell Programming and Scripting

extracting Number variable and the following digits.

HI all, I have output of something like this: crab: ExitCodes Summary >>>>>>>>> 12 Jobs with Wrapper Exit Code : 50117 List of jobs: 1-12 See https:///twiki/something/ for Exit Code meaning crab: ExitCodes Summary >>>>>>>>> 5 Jobs with Wrapper Exit Code : 8001 List of... (20 Replies)
Discussion started by: emily
20 Replies

8. Shell Programming and Scripting

extracting number of rows

if > wc -l data.txt > 100 (meaning there are 100 rows) i want to assgn 100 as n so that if i do >echo n it would give me 100 Thanks (5 Replies)
Discussion started by: johnkim0806
5 Replies

9. Shell Programming and Scripting

Extracting fixed length number from a text file

Hi, I have a text file with sample records as CASE ID: 20170218881083 Original presentment record for ARN not found for Re-presentment I want to extract the 23 digit number from this file. I thought of using grep but initially couldn't extract the required number. However, after... (16 Replies)
Discussion started by: dsid
16 Replies

10. Shell Programming and Scripting

Extracting substring within string between 2 token within the string

Hello. First best wishes for everybody. here is the input file ("$INPUT1") contents : BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY; BASH_FUNC_message_debug%%=() { local -a L_ARRAY; BASH_FUNC_message_end_script%%=() { local -a L_ARRAY; BASH_FUNC_message_error%%=() { local... (3 Replies)
Discussion started by: jcdole
3 Replies
string.h(3HEAD) 						      Headers							   string.h(3HEAD)

NAME
string.h, string - string operations SYNOPSIS
#include <string.h> DESCRIPTION
The <string.h> header defines the following: NULL null pointer constant size_t as described in <stddef.h> ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
memory(3C), strcoll(3C), string(3C), strxfrm(3C), stddef.h(3HEAD), types.h(3HEAD), attributes(5), standards(5) SunOS 5.11 10 Sep 2004 string.h(3HEAD)
All times are GMT -4. The time now is 08:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy