Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
etersoft-build-utils
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
korinf
etersoft-build-utils
Commits
51f078b2
Commit
51f078b2
authored
Jun 21, 2012
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
introduce estrlist for sets operations, use it partially
parent
f4a4d2df
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
12 deletions
+132
-12
estrlist
bin/estrlist
+125
-0
strings
share/eterbuild/functions/strings
+7
-12
No files found.
bin/estrlist
0 → 100755
View file @
51f078b2
#!/bin/bash
# 2009-2010, 2012 Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
# TODO: rewrite with shell commands, perl or C
# Python - http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch16s03.html
# Shell - http://linux.byexamples.com/archives/127/uniq-and-basic-set-theory/
# - http://maiaco.com/articles/shellSetOperations.php
# Perl - http://docstore.mik.ua/orelly/perl/cookbook/ch04_09.htm
# - http://blogs.perl.org/users/polettix/2012/03/sets-operations.html
# http://rosettacode.org/wiki/Symmetric_difference
# TODO: add unit tests
# http://ru.wikipedia.org/wiki/Операции_над_множествами
# Base set operations:
# * union
# "1 2 3" "3 4 5" -> "1 2 3 4 5"
# * intersection
# "1 2 3" "3 4 5" -> "3"
# * relative complement (substracted, difference) ( A ? B – members in A but not in B )
# http://en.wikipedia.org/wiki/Complement_%28set_theory%29
# "1 3" "1 2 3 4" -> "2 4"
# * symmetric difference (симметричная разность) ( A ^ B – members in A or B but not both )
# http://en.wikipedia.org/wiki/Symmetric_difference
# "1 2 3" "3 4 5" -> "1 2 4 5"
filter_strip_spaces
()
{
# possible use just
#xargs echo
sed
-e
"s|
\+
| |g"
|
\
sed
-e
"s|^ ||"
|
sed
-e
"s|
\$
||"
}
strip_spaces
()
{
echo
"
$*
"
| filter_strip_spaces
}
union
()
{
local
i
for
i
in
$@
;
do
echo
"
$i
"
done
|
sort
-u
}
# remove_from_list "1." "11 12 21 22" -> "21 22"
reg_remove
()
{
local
i
local
RES
=
for
i
in
$2
;
do
echo
"
$i
"
|
grep
-q
-w
"
$1
"
||
RES
=
"
$RES
$i
"
done
strip_spaces
"
$RES
"
}
# Args: LIST1 LIST2
# do_exclude_list print LIST2 exclude fields contains also in LIST1
# Example: exclude "1 3" "1 2 3 4" -> "2 4"
exclude
()
{
local
i
local
RES
=
for
i
in
$2
;
do
echo
"
$1
"
|
grep
-q
-w
"
$i
"
||
RES
=
"
$RES
$i
"
done
strip_spaces
"
$RES
"
}
# regexclude_list "22 1." "11 12 21 22" -> "21"
reg_exclude
()
{
local
i
local
RES
=
"
$2
"
for
i
in
$1
;
do
RES
=
$(
reg_remove
"
$i
"
"
$RES
"
)
done
strip_spaces
"
$RES
"
}
# FIXME:
# reg_include "1." "11 12 21 22" -> "11 12"
reg_include
()
{
local
i
local
RES
=
for
i
in
$2
;
do
echo
"
$i
"
|
grep
-q
-w
"
$1
"
&&
RES
=
"
$RES
$i
"
done
strip_spaces
"
$RES
"
}
--help
()
{
echo
"estrlist developed for string list operations. See also cut, join, paste..."
echo
"Usage:
$0
<command> [args]"
echo
"Commands:"
echo
"strip_spaces [args] - remove spaces between words"
echo
"filter_stip_spaces - remove spaces from words from standart input"
echo
"reg_remove <PATTERN> [word list] - remove words containing a match to the given PATTERN (grep notation)"
echo
"exclude <list1> [list2] - print list2 words contains also in list1"
echo
"reg_exclude <PATTERN> [word list] - print only words not matched with PATTERN"
echo
echo
"Examples:"
echo
"
\$
$0
reg_remove
\"
1.
\"
\"
11 12 21 22
\"
"
$0
reg_remove
"1."
"11 12 21 22"
echo
"
\$
$0
exclude
\"
1 3
\"
\"
1 2 3 4
\"
"
$0
exclude
"1 3"
"1 2 3 4"
echo
"
\$
$0
reg_exclude
\"
22 1.
\"
\"
11 12 21 22
\"
"
$0
reg_exclude
"22 1."
"11 12 21 22"
}
COMMAND
=
"
$1
"
if
[
-z
"
$COMMAND
"
]
;
then
echo
"Run with --help for get command description."
exit
1
fi
shift
"
$COMMAND
"
"
$@
"
share/eterbuild/functions/strings
View file @
51f078b2
...
...
@@ -32,23 +32,18 @@ remove_from_list()
# Example: do_exclude_list "1 3" "1 2 3 4" -> "2 4"
do_exclude_list
()
{
local
i
local
RES
=
for
i
in
$2
;
do
echo
"
$1
"
|
grep
-q
-w
"
$i
"
||
RES
=
"
$RES
$i
"
done
strip_spaces
"
$RES
"
$ETERBUILDBIN
/estrlist exclude
"
$@
"
}
# regexp_exclude_list "22 1." "11 12 21 22" -> "21"
regexp_exclude_list
()
{
local
i
local
RES
=
"
$2
"
for
i
in
$1
;
do
RES
=
$(
remove_from_list
"
$i
"
"
$RES
"
)
done
strip_spaces
"
$RES
"
$ETERBUILDBIN
/estrlist reg_exclude
"
$@
"
}
estrlist
(
)
{
$ETERBUILDBIN
/estrlist
"
$@
"
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment