• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

[solved] regular expressions

PNS-Richi

Member
Hallo,

/ordner/ordner.blub

Ich will das zwsichen /ordner/ und .blub auslesen.

z.b. /apps/hosts.allow.frm

dann soll das Ergebnis hosts.allow sein.

danke für eure Hilfe!

lg Richi
 

scummos

Hacker
hmm
also das erste ist einfach
[cmmnd der die ausgabe produziert] | awk -F'/' '{print $2}'
aber das andere?
am punkt kann man nicht schneiden, an der endung nicht... sehe keine möglichkeit...
 

regexer

Advanced Hacker
Sed kann's auch:
Code:
echo /etc/hosts.allow.frm | sed 's#.*/##;s/\.[^.]*$//;'

Frage dich außerdem:
Was soll passieren, wenn der Dateiname mit Punkt beginnt, aber sonst keine weiteren Punkte im Namen hat?
Was soll passieren, wenn der Dateiname gar keinen Punkt im Namen hat?
 

oc2pus

Ultimate Guru
du kannst dir auch mal tt2regex anschauen:
http://packman.links2linux.de/package/txt2regex

Code:
^txt2regex$ is a Regular Expression "wizard", all written with bash2
builtins, that converts human sentences to regexes. With a simple
interface, you just answer to questions and build your own regex for a
large variety of programs, like awk, emacs, grep, perl, php, procmail,
python, sed and vim. There are more than 20 supported programs.
It's bash so download and run, no compilation needed.

und/oder
http://packman.links2linux.de/package/redet
Redet allows the user to construct regular expressions and test them against
input data by executing any of a variety of search programs, editors, and
programming languages that make use of regular expressions. When a suitable
regular expression has been constructed it may be saved to a file.

Redet stands for Regular Expression Development and Execution Tool. For each
program, a palette showing the available regular expression syntax is provided.
Selections from the palette may be copied to the regular expression window with
a mouse click. Users may add their own definitions to the palette via their
initialization file.

Redet also keeps a list of the regular expressions executed, from which entries
may be copied back into the regular expression under construction. The history
list is saved to a file and restored on startup, so it persists across
sessions. So long as the underlying program supports Unicode, redet allows
UTF-8 Unicode in both test data and regular expressions.

damit wird entwerfen von Regular Expressions zum "Kinderspiel" ..
 

regexer

Advanced Hacker
notoxp schrieb:
Frage dich außerdem:
Was soll passieren, wenn der Dateiname mit Punkt beginnt, aber sonst keine weiteren Punkte im Namen hat?
Was soll passieren, wenn der Dateiname gar keinen Punkt im Namen hat?
Code:
 echo /path/keinpunkt | perl -plne 's#.*/##;s/(.+)\.[^.]+$/$1/;'
echo /my/home/.profile  | perl -plne 's#.*/##;s/(.+)\.[^.]+$/$1/;'

Oder vielleicht geht es ja auch ganz einfach mit Linux-Bordmitteln.
Code:
man basename
 
Oben