text="\
1 London Paris |I am the Rock|
2 Moscow Kyiv |I am the Cena|
3 Kharkiv Dnepr |I am the CM Punk|
4 Ottava Amsterdam |I am the Rock|
5 Oslo New-Yourk |I am the Rock|
6 Lviv Varshava |I am the Cena|
7 Berlin Rome |I am the CM Punk|
8 Moscow Oslo |I am the Cena|
9 Kharkiv Kyiv |I am the Brock Lesnar|
"
fsm()
{
awk '{
switch (state) {
case 0:
if (/Rock/) {
out = $0
state = 1
}
break
case 1:
if (/Rock/) {
out = $0;
} else if (/Cena/) {
out = out"\n"$0
state = 2
} else {
out = ""
state = 0
}
break
case 2:
if (/Punk/) {
out = out"\n"$0
print out
out = ""
state = 0
} else {
out = ""
state = 0
}
break
}
}'
}
echo "$text" | fsm
[guest@localhost tmp]$ echo "$text" | fsm
1 London Paris |I am the Rock|
2 Moscow Kyiv |I am the Cena|
3 Kharkiv Dnepr |I am the CM Punk|
5 Oslo New-Yourk |I am the Rock|
6 Lviv Varshava |I am the Cena|
7 Berlin Rome |I am the CM Punk|
[guest@localhost tmp]$
text="\
abc1
abc2
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr1| - |user logged in| -
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr1| - |user changed password| -
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr1| - |user logged off| -
def1
def2
Mon, 1 Aug 2012 00:15:00 +xxxx|1.1.1.1|dnepr2| - |user logged in| -
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr2| - |user logged in| -
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr2| - |user changed password| -
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr2| - |user logged off| -
ghi1
ghi2
"
fsm()
{
awk '{
switch (state) {
case 0:
if (/user logged in/) {
out = $0
state = 1
}
break
case 1:
if (/user logged in/) {
out = $0;
} else if (/user changed password/) {
out = out"\n"$0
state = 2
} else {
out = ""
state = 0
}
break
case 2:
if (/user logged off/) {
out = out"\n"$0
print out
out = ""
state = 0
} else {
out = ""
state = 0
}
break
}
}'
}
echo "$text" | fsm
[guest@localhost tmp]$ echo "$text" | fsm
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr1| - |user logged in| -
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr1| - |user changed password| -
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr1| - |user logged off| -
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr2| - |user logged in| -
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr2| - |user changed password| -
Mon, 1 Aug 2012 00:15:00 +0200|1.1.1.1|dnepr2| - |user logged off| -
[guest@localhost tmp]$
get_proxy_list() {
savefile=~/.PROXY_LIST
date=$(date +%d.%m.%Y)
url="http://site.com/proxy/list_${date}.txt"
...
}
make_dmy_date() {
date "+%d.%m.%Y"
}
make_proxy_url() {
echo "http://site.com/proxy/list_$(make_dmy_date).txt"
}
make_proxy_ofname() {
echo "~/.PROXY_LIST"
}
get_proxy_list() {
url=$1
savefile=$2
...
}
get_proxy_list `make_proxy_url` `make_proxy_ofname`
Кто может подсказать в какую сторону копать, какие журналы посмотреть?
и как дальше работать с $temp ?
echo "$temp" | что-то работает дальше
[guest@localhost ~]$ text=$(head -3 /etc/passwd)
[guest@localhost ~]$
[guest@localhost ~]$ echo "$text"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[guest@localhost ~]$
[guest@localhost ~]$ echo "$text" | grep oo
root:x:0:0:root:/root:/bin/bash
[guest@localhost ~]$
text="\
abc
hello: \"\"
def
hello: \"\"
ghi
hello: \"\"
jkl
hello: \"\"
mno\
"
echo "$text"
echo "$text" | sed '
/hello: ""/ {
x
/^\.$/ {
x
s/""/"world"/
x
}
s/^/./
x
}
'
[guest@localhost sh]$ text="\
> abc
> hello: \"\"
> def
> hello: \"\"
> ghi
> hello: \"\"
> jkl
> hello: \"\"
> mno\
> "
[guest@localhost sh]$
[guest@localhost sh]$ echo "$text"
abc
hello: ""
def
hello: ""
ghi
hello: ""
jkl
hello: ""
mno
[guest@localhost sh]$
[guest@localhost sh]$ echo "$text" | sed '
> /hello: ""/ {
> x
> /^\.$/ {
> x
> s/""/"world"/
> x
> }
> s/^/./
> x
> }
> '
abc
hello: ""
def
hello: "world"
ghi
hello: ""
jkl
hello: ""
mno
[guest@localhost sh]$
func()
{
cat <<EOF
int i;
cout << "hello!" << endl;
printf("%s", "hello");
printf("%s", "world");
EOF
}
func
func | sed '/hello/ s%^%//%'
[guest@localhost sh]$ func()
> {
> cat <<EOF
> int i;
> cout << "hello!" << endl;
> printf("%s", "hello");
> printf("%s", "world");
> EOF
> }
[guest@localhost sh]$
[guest@localhost sh]$ func
int i;
cout << "hello!" << endl;
printf("%s", "hello");
printf("%s", "world");
[guest@localhost sh]$
[guest@localhost sh]$ func | sed '/hello/ s%^%//%'
int i;
// cout << "hello!" << endl;
// printf("%s", "hello");
printf("%s", "world");
[guest@localhost sh]$
#!/bin/bash
test_parameter()
{
echo "$1" | grep -q '\(video\|audio\|pic\)\*'
}
if ! test_parameter "$1"; then
echo error
else
echo success
fi
exit 0
[guest@localhost sh]$ ./t.sh video
error
[guest@localhost sh]$ ./t.sh video*
success
[guest@localhost sh]$ ./t.sh audio
error
[guest@localhost sh]$ ./t.sh audio*
success
[guest@localhost sh]$ ./t.sh x
error
[guest@localhost sh]$
#!/bin/bash
error()
{
echo "error: $1" 1>&2
}
ok()
{
echo "success: $1" 1>&2
}
test_parameter()
{
echo "$1" | grep -q '\(video\|audio\|pic\)\*'
}
main()
{
if ! test_parameter "$1"; then
error "incorrect parameter: \"$1\""
else
ok "parameter is correct"
fi
}
main "$@" || exit 1
exit 0
[guest@localhost sh]$ ./t.sh
error: incorrect parameter: ""
[guest@localhost sh]$ ./t.sh video
error: incorrect parameter: "video"
[guest@localhost sh]$ ./t.sh video*
success: parameter is correct
[guest@localhost sh]$ ./t.sh audio
error: incorrect parameter: "audio"
[guest@localhost sh]$ ./t.sh audio*
success: parameter is correct
[guest@localhost sh]$ ./t.sh pic
error: incorrect parameter: "pic"
[guest@localhost sh]$ ./t.sh pic*
success: parameter is correct
[guest@localhost sh]$ ./t.sh x
error: incorrect parameter: "x"
[guest@localhost sh]$
#!/bin/bash
get_url()
{
echo "$1"
}
get_subdir()
{
echo "$1" | sed 's/.*\.\([0-9]*\)\.mp4$/\1/'
}
main()
{
ifname="links.txt"
odir="videos"
ofname="links.txt"
[ ! -d "$odir" ] && mkdir "$odir"
cat "$ifname" | while read line; do
ourl=`get_url "$line"`
osubdir=`get_subdir "$line"`
[ ! -d "$odir/$osubdir" ] && mkdir "$odir/$osubdir"
opath="$odir/$osubdir/$ofname"
echo "$ourl" >> "$opath"
done
}
main "$@" || exit 1
exit 0
[guest@localhost ~]$ s='hello allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> hello'
[guest@localhost ~]$
[guest@localhost ~]$ src='allow="127\\\.\\d+\\\.\\d+\\\.\\d+|::1|0:0:0:0:0:0:0:1" />'
[guest@localhost ~]$ dst='allow="^.\\*$" />'
[guest@localhost ~]$
[guest@localhost ~]$ echo "$s"
hello allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> hello
[guest@localhost ~]$
[guest@localhost ~]$ echo "$src"
allow="127\\\.\\d+\\\.\\d+\\\.\\d+|::1|0:0:0:0:0:0:0:1" />
[guest@localhost ~]$
[guest@localhost ~]$ echo "$dst"
allow="^.\\*$" />
[guest@localhost ~]$
[guest@localhost ~]$ echo "$s" | sed "s%$src%$dst%g"
hello allow="^.\*$" /> hello
[guest@localhost ~]$
[guest@localhost t]$ ll
итого 4
-rw-rw-r--. 1 guest guest 0 сен 30 13:08 a a.txt
-rw-rw-r--. 1 guest guest 0 сен 30 13:06 a.txt
-rw-rw-r--. 1 guest guest 0 сен 30 13:06 b.txt
-rw-rw-r--. 1 guest guest 0 сен 30 13:06 c.txt
drwxrwxr-x. 2 guest guest 4096 сен 30 13:19 d
[guest@localhost t]$
[guest@localhost t]$ ls
a a.txt a.txt b.txt c.txt d
[guest@localhost t]$
[guest@localhost t]$ files=$(find -name '*.txt')
[guest@localhost t]$
[guest@localhost t]$ echo "$files" | sed 's/.*/mv "&" d/'
mv "./b.txt" d
mv "./a.txt" d
mv "./c.txt" d
mv "./a a.txt" d
[guest@localhost t]$
[guest@localhost t]$ echo "$files" | sed 's/.*/mv "&" d/' | sh
[guest@localhost t]$
[guest@localhost t]$ ls
d
[guest@localhost t]$ ls d
a a.txt a.txt b.txt c.txt
[guest@localhost t]$
[guest@localhost t]$ ll d
итого 0
-rw-rw-r--. 1 guest guest 0 сен 30 13:08 a a.txt
-rw-rw-r--. 1 guest guest 0 сен 30 13:06 a.txt
-rw-rw-r--. 1 guest guest 0 сен 30 13:06 b.txt
-rw-rw-r--. 1 guest guest 0 сен 30 13:06 c.txt
[guest@localhost t]$