Got it.
$1!=0&&$2==0{ b[$3]-=$4;}
$1==0&&$2==0{ b[$3]+=$4;}
$1==0&&$2!=0{ b[$3]-=$4;print $3, b[$3] }
It works for this particular case.
I am still looking for alternative solutions.
Thanks.
I could use that approach.
The blocks are not necessarily 9 lines. It could change from one block to another. My bad I did not specify that. Still I believe I can use your approach . Will post back as soon as I get some solution.
I have four columns input data.x,y,z b,c,d are some numbers not necessarily the same.
x 0 z1 bl
x 0 z2 cl
x 0 z3 dl
0 0 z1 bc
0 0 z2 cc
0 0 z3 dc
0 y z1 br
0 y z2 br
0 y z3 br
The data could be separated in blocks of triplets for which the third column is the same.
The sequence z1,z2,z3 would...
Hope I am not deviating much from the thread promp
Recently I had to setup a cronjob where periodically would copy the file over scp.The command portion of my cronttab looked something like that.
/usr/bin/scp -i /home/user/.ssh/id_dsa /tmp/file.dat server.net:~/
If I were to execute the same...
Thanks again feherke.
The deisired output for regex1 regex2 would be
1 11 12
2 21 22
3 31 32
To explain.
First value of each row is the block number.
Values two three are the values of the fields right under the regex1 and regex2.
Thanks.
My initial try was this.
awk '{for(i=1;i<=NF;++i)if(match($i,/regex1/)); getline; print $i }'
What I don't understand is why the /regex1/ outside the {...} block is needed.
If you remove it awk should process that for loop inside the {...} for each line of the input file and yet if I...
simple example inputfile
regex1 regex2 regex3
1 2 3
4 5 6
regex1 regex3 regex2
aa bb cc
7 8 9
If I want to print the next line after the regex2.
In my inptut file
awk '/regex1/{getline;print $0}' inputfile
How can I print only the...
try denyhosts
http://denyhosts.sourceforge.net/
Adds ip's to //etc/hosts.deny after X number of unsuccessful login attempts for the period of the last Y days.
Highly configurable with many options.
or
sshutout
Blocks ip's on the iptables level...
Consider the input file where the last $2==y entries are consecutive.
1 y 10
2 y 11
3 y 10
4 n 12
5 n 22
6 y 12
7 y 12
8 n 33
9 y 12
10 y 10
11 y 10
12 y 10
13 y 10
14 n 12
Now the output of the the second code will give
1
2
3
6 - 7
9
10
The last line is missing...
Sample input
1 y 10
2 y 11
3 y 10
4 n 12
5 n 22
6 y 12
7 y 12
8 n 33
9 y 12
10 y 10
11 y 10
12 y 10
13 y 10
14 y 11
If I want to extract list of lines for which $2==y I can do.
awk '$2=="y"{print $1}' list
1
2
3
6
7
9
10
11
12
13
14
What I really need is to print...
Thank you. I was not aware of the FILENAME variable.
Need to do some more awk RTFM.
Just for completeness of my initial try.
awk '/cat=b/{system("cp " FILENAME " dir_b/") }' file*
Which is still inefficient.
Based on Annihilannic solution, but using system(...) instead
awk -F=...
Here is incomplete awk solution
awk 'NR==1 && /"cat=a"/{} END{print system("cp " ARGV[2] " dir_a/") }' file*
In that case will move file_b
Just need a way to get the right filenames that are matching the cat=a regex and call them instead the ARGV[2] at the END{...}
I have non awk solution.
Let say you have file_a file_b file_c
file_a looks like this
cat=a
text in file a
file_b looks like this
cat=b
text in file b
file_c looks like this
cat=c
text in file c
and you want to move the file containing cat=a into directory called dir_a.
This should do the...
Can you explain this line
/#S [0-9]+ / && ($2 in wanted) { section=$2 }
I know that it turns on the section switch and assigns value to section to be used in the name of the output file later.
What that plus after the regex list means?
Is it possible to use something like this instead...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.