Hello friends,I am new to Unix programming.
how do I achieve the following in Unix shell script (I am running ksh on AIX)
extract the number from name of file?
My file format is like "LongFileName-1234.020614-221030.txt"
now I want to extract value which is between (-) hyphen and (.) dot i.e. 1234,
once I get that value I need to assign it to variable and need to compare against oracle db.
i am looking for solution which works if value goes from 4 digit to 5 digit and onward. i.e. consider following file names
I appreciate your responses.
In ksh/bash:
The first uses the variable chewers: ${#NamePattern} ${#NamePattern} ${##NamePattern} ${%NamePattern} ${%%NamePattern} I use the mnemonic "Pound soft or hard on the nose, or take your small or big % off the end." The patterns are file flavored, with metacharacters * ? [] but not [^].
The second says the '-' and '.' is now a word separator like space (but just within the (subshell), we do not want it 'from now on and forever'), so you can read each line as 4 words into 3 variables.
Sed is instructed: substitute for "from beginning of line, anything not a '-' up to a '-', start a substring capture, anything not a dot, end substring, everything else", put back just the substring captured. The regex '.*' is greedy but the '^' BOL and '[^-]*' not a hyphen in any number is more restrained. Regex uses '.' where file patterns uses '?', '.*' where file uses '*', has the negative list and other more powerful metastrings. I expect I overlooked bash ways to use regex in shell.
Last edited by DGPickett; 10-10-2014 at 04:39 PM..
Thank you Singh sir, I will do the same. will try the script and post the response.
---------- Post updated at 03:45 PM ---------- Previous update was at 03:40 PM ----------
Thnx a lot DGPickett ! I will try the script and post the result.
will it work even if the numbers between (-) and (.) does not follow any pattern? I mean if the numbers are like 231, 4823, 89103 will it still give same output ?
Yes, ther sed regex says anything but a dot '[^.]' in any quantity '*'. We could have been tighter and said just numbers '[0-9]'. The shell variable grinders are gentle up to the '-': '#*-' and agressive from end back to '.': '%%.*'. The two dots and two hyphens made the more complex and carefully limited expressions necessary.
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
I have this script that will monitor filesystems and send me e-amil alerts.
#! /bin/ksh
DIST_LIST=monitor@...com
WORKDIR=/home/monitor
WARNLEVEL=90
MAIL_SUBJ="filesystems monitor on "$(hostname)
... (3 Replies)
Hi,
I developed a script which finally originates a similar output:
net0:up,Tx=475198bps,Rx=31009bps net1:up,Tx=39596bps,Rx=35678bps
Of course the figures change and also the amount of interfaces (ex: could be more then net0 and net1). This is done automatically.
The next step i'm... (4 Replies)
Hi,
I am trying to grep/extract the number list from this log file, can I get some help on this. I can grep the word 'href' to see the numbers, but it is resulting with the complete line.
Content of my file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>... (4 Replies)
Hi All,
I have a file which is like this:
rows.dat
1 2 3 4 5 6
3 4 5 6 7 8
7 8 9 0 4 3
2 3 4 5 6 7
1 2 3 4 5 6
I have another file with numbers like these (numbers.txt):
1
3
4
5
I want to read numbers.txt file line by line. The extract the row from rows.dat based on the... (3 Replies)
Hello All,
I need to extract lines from a file that contains ALPHANUMERIC and the length of Alphanumeric is set to 16. I have pasted the sample of the lines from the text file that I have created.
My problem is that sometimes 16 appears in other part of the line. I'm only interested to... (14 Replies)
I need to extract all the p-value numbers and the rho numbers from a .txt file and write them as coma separated values in a new file. Ideally I would get two files in the end, one for p- values and one for rho. Any suggestions? I appreciate your help!!!
The .txt file looks essentially like this... (5 Replies)
Just wondering if someone could assist me with shell script I'm trying to write. I need to read the final column of a text file (shown below) and workout what the average number is. The text file will have a variable number of lines, I just want the script to pull out the values in the final field... (14 Replies)
Hi ppl,
I am a bit lost on this...can some one assist. I know this can be down with awk or sed, but i cant get the exact syntax right.
I need to only extract the numbers from a signle word ( eg abcd.123.xyz )
How can i extract 123 only ?
Thanks (14 Replies)
Hi all,
Please some help over here. I have a Sales.txt file containing info in blocks for
every sold product in the pattern showed below (only for 2 products).
NEW BLOCK
SALE DATA
PRODUCT SERIAL
79833269999 146701011945004
.Some other data
.Some... (17 Replies)
It may sounds too easy but appreciate any help on this..
i have a file with the below details:
******************************************
Please find the locked pernr details for the Time evaluation
Personnel number could not be locked
Person rejected: 04552737
Personnel number could not... (4 Replies)