AWK: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Weitere Links
(Die Seite wurde neu angelegt: Table of Contents * Why learn AWK? * Basic Structure * Executing an AWK script * Which shell to use with AWK? * Dynamic Variables * The Essenti...) |
K (typo) |
||
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
This awk program deletes C-style comments (‘/* ... */’) [http://www.gnu.org/manual/gawk/html_node/Plain-Getline.html#Plain-Getline Link]<br> | |||
negativ from above (prints everything between aAa and bBb) | |||
<source lang="bash">#!/usr/bin/awk -f | |||
{ | |||
if ((t = index($0, "aAa")) != 0) { | |||
print $0 | |||
# value of `tmp' will be "" if t is 1 | |||
tmp = substr($0, 1, t - 1) | |||
u = index(substr($0, t + 2), "*/") | |||
offset = t + 2 | |||
while (u == 0) { | |||
if (getline <= 0) { | |||
m = "unexpected EOF or error" | |||
m = (m ": " ERRNO) | |||
print m > "/dev/stderr" | |||
exit | |||
} | |||
print $0 | |||
u = index($0, "bBb") | |||
offset = 0 | |||
} | |||
# substr expression will be "" if */ | |||
# occurred at end of line | |||
#$0 = tmp substr($0, offset + u + 2) | |||
} | |||
#print $0 | |||
}</source> | |||
<br> | |||
[[ | = Weitere Links<br> = | ||
*[http://www-e.uni-magdeburg.de/urzs/awk/ awk - Eine Einführung]<br> | |||
*[http://www.grymoire.com/Unix/Awk.html Awk - A Tutorial and Introduction]<br> | |||
[[Category:Linux]] [[Category:Tips_und_Tricks]] |
Aktuelle Version vom 26. August 2009, 19:50 Uhr
This awk program deletes C-style comments (‘/* ... */’) Link
negativ from above (prints everything between aAa and bBb)
#!/usr/bin/awk -f
{
if ((t = index($0, "aAa")) != 0) {
print $0
# value of `tmp' will be "" if t is 1
tmp = substr($0, 1, t - 1)
u = index(substr($0, t + 2), "*/")
offset = t + 2
while (u == 0) {
if (getline <= 0) {
m = "unexpected EOF or error"
m = (m ": " ERRNO)
print m > "/dev/stderr"
exit
}
print $0
u = index($0, "bBb")
offset = 0
}
# substr expression will be "" if */
# occurred at end of line
#$0 = tmp substr($0, offset + u + 2)
}
#print $0
}