samedi 25 avril 2015

Get IP address in a string


I'm new to this web site and hope I'm doing this correctly.

I'm looking for some sort of PHP-code to scan my /var/log/secure to filter breakin attempts. Below are just some examples of string that need to be searched and get the IP address ONLY. I'm using 0.0.0.0 as an example of an IP address and not the actual IP.

Failed password for invalid user admin from 0.0.0.0 port 3108 
Invalid user ubnt from 0.0.0.0
pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=0.0.0.0


Building the find regex parameters in shell scripts


I'm trying to build the parameters used in the regex expression in a find command from a shell script but it seems does not work.

Objective of this shell script is to be able to find some files according with specified parameters in shell script.

The shell script looks like something like:

#!/bin/bash
IDS=$1
FOLDER="/tmp"
MODULENAMEPATTERN=`echo $IDS | sed "s/,/|/g"`
MODULENAMEPATTERN=".*\\.\\($MODULENAMEPATTERN\\)"
echo "find command: find $FOLDER -follow -type f -regex \"$MODULENAMEPATTERN.suffix\""

for FILEFOUND in `find $FOLDER -follow -type f -regex "$MODULENAMEPATTERN.suffix"`; do
    echo $FILEFOUND
done;

To launch it, I use the following command:

./test pattern1,pattern2

it generate the following output:

find command: /tmp -follow -type f -regex ".*\.\(pattern1\|pattern2\).suffix"

But nothing more.

Unfortunately, if I execute the generated find command from a terminal, it generate the following output:

/tmp/folder1/.pattern1.suffix
/tmp/folder2/.pattern1.suffix
/tmp/folder2/.pattern2.suffix

I do know exactly where is my problem. Can you help me?

Regards


Space before sentence and after sentence?


I've got this script:

<input type="text" name="lastnamename" pattern="[^\s]*" title="Delete space before or after sentence!" style="text-transform:uppercase" required>

This pattern "[^\s]*" shows every spaces which has been made in sentence _Adam_Sandler_. I need pattern which shows only _Adam Sandler_ these spaces BEFORE SENTENCE, AND AFTER SENTENCE.


Regular expression to compare the first n characters of a string array


I am working on some auto complete example and i want only the words starting with the entered text.

EG:-if i type "al" then i want only first two as my results not the 3rd one

**Al**abama
**Al**aska
c**al**lifornia


Import custom text format without separators


I would like import this .txt file format to SQL Server Table or to convert each block of text to pipe separated line.

Which tools or C# solution suggests you to resolve this issue?

Any suggestions would be appreciated.

Thank You.

=================
INPUT (.txt file)
=================
ID: 37
Name: Josephy Murphy
Email: jmurphy@email.com
Description: bla, bla, bla, bla...

ID: 38
Name: Paul Newman
Email: pnewman@email.com
Description: bla, bla, bla, bla...

:
:

=========================
OUTPUT (SQL Server Table)
=========================

ID | Name           | Email             | Description  
37 | Josephy Murphy | jmurphy@email.com | bla, bla, bla, bla...
38 | Paul Newman    | pnewman@email.com | bla, bla, bla, bla...

:
: 


RegEx Notepad++ Python Script to change Date Format


Gang...I need a notepad++ python script teaching moment.

I want to find and replace a date format (MM/DD/YY and replace with YYYY-MM-DD) another. In NotePad++ RegEx I can do this with

Find: (([0-9]+)/+([0-9]+)/+([0-9]+))

Replace: 20\3-\1-\2

Would someone show me a notepad++ python script that will accomplish the same thing? I think my knowledge gap is in group replacement


Linux CLI change price (awk or sed?)


I have price strings formatted as $25.00 in various html files. I would like to use the Linux command line (BASH, presumably with awk or sed) to increase each price by a certain dollar amount ($3 in this case).

In short, I need to find $nn.00 and replace it with $(n+3)n.00

Started to put it together but I don't know how to add 3 sed -r 's/([^$][0-9][0-9][.]00). ????' file.html

Thanks!