-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstacker.awk
More file actions
40 lines (35 loc) · 698 Bytes
/
Copy pathstacker.awk
File metadata and controls
40 lines (35 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
BEGIN {
FS="\n" ## fields are separated by newline
OFS="\n"
stack = ""
have = 0
lines = 20
}
{
if (string == $0) { ## string is an execution variable (-v string="string")
have = 1
}
if (stack == "") {
stack = $0
}
else { stack = stack FS $0 }
}
END {
if (!have) { ## if string is not in the stack prepend it
$0 = string FS stack
}
# else { $0 = stack }
else { exit } ## string is in the stack, do nothing
if (NF < lines) { lines = NF } ## output no more then var lines
for (x = 1; x <= lines; x++) {
# output = output $x
print $x
# if (x < lines) {output = output FS}
}
#print output
system("")
#cmd = "cat > stack.db"
#print msg | cmd
#system("")
#close(cmd)
}