Search Results

Search: Posts Made By: ripat
112,285
Posted By ripat
My bad, am I so rusted in awk? Nice catch.
My bad, am I so rusted in awk? Nice catch.
112,285
Posted By ripat
As no sample files were provided I made some...
As no sample files were provided I made some assumptions on their contents. To put you on track:
headers file
$ cat headers
H3
H4
H1
H2

input_file
$ cat input_file
H1 H2 H3 H4
01 02 03...
6,301
Posted By ripat
In that case the example that I gave above should...
In that case the example that I gave above should put you on track. Split the AGRN or whatever part of $5 that could possibly been *exactly* matched by the search pattern. This will avoid searching a...
6,301
Posted By ripat
If $5 can always be spilt on the hyphen i.e....
If $5 can always be spilt on the hyphen i.e. AGRN-6|gc=75 to AGRN-6|gc=75 this could speed up the process.

To put you on track:



BEGIN{FS="[\t| -]+"}

FNR==NR {
s[$0]=1
next
}

# if...
6,301
Posted By ripat
Can you post sample files? Is the $5 string...
Can you post sample files?

Is the $5 string longer than the searched pattern?
29,023
Posted By ripat
... and for a string with a given length: ...
... and for a string with a given length:


# length 5
head -3 /dev/urandom | tr -cd '[:alnum:]' | cut -c -5

# length 8
head -3 /dev/urandom | tr -cd '[:alnum:]' | cut -c -8
1,550
Posted By ripat
Hello Forum! Back after a long absence. Awk...
Hello Forum!

Back after a long absence. Awk is fun and I needed to flex my brain cells. Here is mine:

awk '$2~/^F509/{i++; split($2,a,"="); $2=a[1]"="a[2]+i}1' FS=^ OFS=^ file
1,660
Posted By ripat
Indeed and that's exactly what I find weird. With...
Indeed and that's exactly what I find weird. With code[$3] in the second block I was expecting awk to *evaluate* the value of code[$3] *not* to assign any value to it, albeit NULL.

awk...
1,660
Posted By ripat
Strange behaviour of arrays in awk
Imagine 2 files f1 f2:

file1_l1_c1 code_to_find file1_l1_c3
file1_l2_c1 file1_code2 file1_l2_c3
file1_l3_c1 file1_code3 file1_l3_c3


file2_l1_c1 file2_l1_c2 code_to_find
file2_l2_c1...
36,866
Posted By ripat
Brilliant. Works much better than my original...
Brilliant. Works much better than my original range2cidr() function. I just edited my post above to include your function.

Well done!
36,866
Posted By ripat
Convert ip ranges to CIDR netblocks
Hi,

Recently I had to convert a 280K lines of ip ranges to the CIDR notation and generate a file to be used by ipset (netfilter) for ip filtering.

Input file:
000.000.000.000 -...
2,273
Posted By ripat
ok, I see where the problem is. The ternary...
ok, I see where the problem is. The ternary condition was not expecting to see zero values.

Try this:
{nbr[$1]++; a[$1]= (a[$1]!="") ? a[$1]"@"$2 : $2; sum[$1]+=$2} # NEW


END {
for (key...
2,273
Posted By ripat
Place your condition on the length higher in the...
Place your condition on the length higher in the code and also change the way to determine that length. Only marginal speed increase to be expected.

sort f -k1,1 -k2,2n | awk '
{nbr[$1]++; a[$1]=...
2,273
Posted By ripat
Is it this that you are after? sort file...
Is it this that you are after?

sort file -k1,1 -k2,2n | awk '
{nbr[$1]++; a[$1]= a[$1] ? a[$1]"@"$2 : $2; sum[$1]+=$2}

END {
for (key in a) {
split(a[key], b, "@")
len =...
2,639
Posted By ripat
True. Just adapted my snippet. $ awk...
True. Just adapted my snippet.

$ awk 'NR>1{if($0~/PATTERN/)b=b"@@";print b}{b=$0}END{print b}' f
2,639
Posted By ripat
$ cat f line one line to match PATTERN last...
$ cat f
line one
line to match PATTERN
last line


$ awk 'b{if($0~/PATTERN/)b=b"@@";print b}{b=$0}END{print b}' f
line one@@
line to match PATTERN
last line
1,971
Posted By ripat
The idea is to store every line in a buffer...
The idea is to store every line in a buffer variable {l=$0}

For every line seen == to the previous line stored in the buffer l==$0 and containing FUNC &&/FUNC/ skip that line {next} and start all...
1,971
Posted By ripat
Another way: awk...
Another way:

awk 'l==$0&&/FUNC/{next}{l=$0}1' file
1,664
Posted By ripat
Alternative: awk...
Alternative:

awk '$3~"A"{A[$1"|"$2]+=$4}$3~"I"{I[$1"|"$2]+=$4}END{for(a in A)print a,A[a],I[a]}' FS="|" OFS="|" file \
| sort -t"|" -k1,1 -k2,2
3,720
Posted By ripat
Yet another way of doing it: FNAME="s1.txt...
Yet another way of doing it:

FNAME="s1.txt s2.lst s3.cvs s4.lst"

FILE_PATTERN="lst"
i=0
for f in $FNAME;do
[ ${f##*.} = $FILE_PATTERN ] && FILE[$i]=$f && i=$((i+1))
done
9,323
Posted By ripat
:confused: Useless use of cat and awk...
:confused:

Useless use of cat and awk instead of head.
6,218
Posted By ripat
Alternative with sort: ls /home/kpp/* | sort...
Alternative with sort:

ls /home/kpp/* | sort -k1.5 -k1.1,1.2 -k1.3,1.4 | tail -n 1
2,945
Posted By ripat
You should work with private/public keys to avoid...
You should work with private/public keys to avoid the login and use scp instead of sftp.
8,973
Posted By ripat
Great! Thanks. Now I only have to take a...
Great! Thanks.

Now I only have to take a deep breath and dive into XLS. It looks like black magic to me. It took me a couple of months to get use to CSS and now XLS...

If you know a good step...
8,973
Posted By ripat
Could xsltproc be able to extract data despite...
Could xsltproc be able to extract data despite that multiple namespace thing?
Showing results 1 to 25 of 500

 
All times are GMT -4. The time now is 07:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy