07-20-2007
Stripping all content but an integer
Hello! I have content in a log file that consists of a lot of spaces before and after a 3 digit integer which I need to strip out before I can use the file. The number of digits can change. When I had my logic in a 'for' loop and could output into another file, it was fine. but it turns out that I will only have 1 line now and don't need the for loop. I have tried a lot of different logic for grepping using the 'x' switch and it didn't work outside of the loop. I tried the E switch as well. This is what I had that worked inside of a for loop, any ideas on how to strip the spaces from the integer? I tried taking just that one line below with the grep, I tried using 'cat' instead of 'echo', nothing worked:
SQL_COUNT=`cat ${LOGPATH}/sql_count.log`
NUM_LOG=${LOGPATH}/num.log
for x in ${SQL_COUNT}
do
echo $x | grep -x '[0-9]*'
done > ${NUM_LOG}
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
How would I strip a date field? For example, if I have
TODAY defined as the following: TODAY=`date +"%m/%d/%y"`,
TODAY is assigned the value 11/01/03 on Nov 1, 2003
How would I strip the first 2 bytes? (11)?
Thank you in advance for the help. (6 Replies)
Discussion started by: Latha Nair
6 Replies
2. UNIX for Dummies Questions & Answers
Hi,
how can i strip the last line off my file using shell script?
Thanks and Regards
Vivek.S (3 Replies)
Discussion started by: vivekshankar
3 Replies
3. UNIX for Dummies Questions & Answers
can anyone help me with stripping an absolute filepath? I did a search on this topic but didnt find anything but maybe I didn't look hard. Anyway, would really appreciate it if anyone could help me. I am a new unix user so this might be a simple issue but I am stuck, don't really understand the use... (4 Replies)
Discussion started by: Ecclesiastes
4 Replies
4. Shell Programming and Scripting
we are ftping zipped up files from the development server to the production server daily.The files are in this format filename.dat.20061231.12131.gz
I have to unzip the file (i can do that with gunzip) and then strip out the timestamp after the .dat extension.
I can do something like this
... (4 Replies)
Discussion started by: mervin2006
4 Replies
5. Shell Programming and Scripting
Hi All;
Having a problem with a file..
the file contains the following data... (a snapshot)
1331F9E9DB7C2BB80EAEDE3A8F043B94,AL7 1DZ,M,50
186FDF93E1303DBA217279EC3671EA91,NG5 1JU,M,24
3783FFAF602015056A8CD21104B1AAAF,CH42 4NQ,M,17
It has 3 columns sepreated by a ,
the second column... (7 Replies)
Discussion started by: Zak
7 Replies
6. Shell Programming and Scripting
I have a variable that has an absolute path for a file on my computer. This dynamically changes. Is there a way I can assign two new variables from that one?
variable: /Users/keith/Desktop/test/file.mov
1) filename - no path or extention ....so just....file
2) path no filename or... (3 Replies)
Discussion started by: mainegate
3 Replies
7. UNIX for Dummies Questions & Answers
Hello, I am the CEO of Grand Tech Corporation. We are launching Linux NT and forgive me, but I do not know how to strip binaries down in Mandriva Linux. Can someone tell me a way to?:b: (2 Replies)
Discussion started by: Linux NT
2 Replies
8. Solaris
Hi All,
What is the difference between stripping and mirroring?
Thanks,
Rafi. (3 Replies)
Discussion started by: rafidba.alvi
3 Replies
9. Shell Programming and Scripting
I'm using a shell script to get user input with this command:
read UserInput
I would then like to take the "UserInput" variable and strip out all of the following characters, regardless of where they appear in the variable or how many occurrences there are:
\/":|<>+=;,?*@
I'm not sure... (5 Replies)
Discussion started by: nrogers64
5 Replies
10. Shell Programming and Scripting
hi,
how to I do this?
i="4.000"
if ; then
echo "smaller"
fi
how do I convert the "4.000" to 4?
Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies
LEARN ABOUT DEBIAN
algorithm::checkdigits::mbase_002
CheckDigits::MBase_002(3pm) User Contributed Perl Documentation CheckDigits::MBase_002(3pm)
NAME
CheckDigits::MBase_002 - compute check digits for blood bags (DE), BZUe (DE), VAT Registration Number (DE)
SYNOPSIS
use Algorithm::CheckDigits;
$bb = CheckDigits('blutbeutel');
if ($bb->is_valid('2761011234567893')) {
# do something
}
$cn = $bb->complete('276101123456789');
# $cn = '2761011234567893'
$cd = $bb->checkdigit('2761011234567893');
# $cd = '3'
$bn = $bb->basenumber('2761011234567893');
# $bn = '276101123456789';
DESCRIPTION
ALGORITHM
1. Start with values P = 10, S = 0.
2. Beginning left you do the following for all digits
1. S = (P + digit) modulo 10
2. If S is 0 then S = 10.
3. P = (2 * S) modulo 11
3. The check digit is (11 - P) modulo 10.
METHODS
is_valid($number)
Returns true only if $number consists solely of numbers and the last digit is a valid check digit according to the algorithm given
above.
Returns false otherwise,
complete($number)
The check digit for $number is computed and concatenated to the end of $number.
Returns the complete number with check digit or '' if $number does not consist solely of digits and spaces.
basenumber($number)
Returns the basenumber of $number if $number has a valid check digit.
Return '' otherwise.
checkdigit($number)
Returns the checkdigit of $number if $number has a valid check digit.
Return '' otherwise.
EXPORT
None by default.
AUTHOR
Mathias Weidner, <mathias@weidner.in-bad-schmiedeberg.de>
SEE ALSO
perl, CheckDigits, www.pruefziffernberechnung.de, www.eurocode.org.
perl v5.10.0 2008-05-17 CheckDigits::MBase_002(3pm)