06-06-2008
extracting a number from a string
Hi everyone,
I have a string as follow
ts1n65ulpa4096x16m16_130a_ss1p08v125c
i would like to extract 4096 and 16 from string and save it into two variable. but this string could also have the form
ts1n65ulpa32x16m16_130a_ss1p08v125c
therefore the number before "x" could be 2 or 3 digits. i use the following but this code is not able to extract more than one digit before "x"
echo "ts1n65ulpa4096x16_130a_ss1p08v125c" | sed -e 's/^[a-z0-9]*\([0-9][0-9]*x[0-9]*\).*/\1/'
the output is
6x16
which is missing 409 as the number before "x"
could anyone help me with this
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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
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
( 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
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
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
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
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
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
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
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