Visit Our UNIX and Linux User Community

Search Results

Search: Posts Made By: ripat
4,462
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...
27,906
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 -...
1,537
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]=...
1,537
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 =...
999
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...
999
Posted By ripat
Another way: awk...
Another way:

awk 'l==$0&&/FUNC/{next}{l=$0}1' file
6,951
Posted By ripat
:confused: Useless use of cat and awk...
:confused:

Useless use of cat and awk instead of head.
1,549
Posted By ripat
On sample file : ...
On sample file :

Account_id|Trip_Org|Trip_Dest|City|Hotel_Nm
123|DFW|CHI|Dallas|Hyatt
123|LAS|LPA|Vegas|Hyatt Palace
124|4_DFW|4_CHI|4_Dallas|4_Hyatt
124|4_LAS|4_LPA|4_Vegas|4_Hyatt Palace
...
6,687
Posted By ripat
How about this one? awk...
How about this one?
awk '!$2{$2="n/a"}!$3{$3="n/a"}1' FS=, OFS=, file

Did I win the contest of who has the shortest? ^_^
612
Posted By ripat
One way of doing it: awk '/kpt/{print...
One way of doing it:

awk '/kpt/{print $0;next}{printf $0}!(NR%6){print ""}' file
1,854
Posted By ripat
A possible alternative: printf "%s\n"...
A possible alternative:

printf "%s\n" /tmp/dsd*.txt |
awk -F"dsd" '{FS="_";$0=$0;a[$2]++}END{for (i in a) {cmd="cat /tmp/dsd*_"i" > /tmp/dsd_"i"";system(cmd)}}'
2,288
Posted By ripat
How about: awk 'NR>1{print $1,$4,$6,$8}'...
How about:

awk 'NR>1{print $1,$4,$6,$8}' RS="QUIT q\n"
2,113
Posted By ripat
It's a forced type casting that I occasionally...
It's a forced type casting that I occasionally use in spread sheets to force a numeric value. I don't think it is documented anywhere. I just gave it a try in awk and it works.
2,113
Posted By ripat
Try this: awk -F"|" '/green/ {print...
Try this:

awk -F"|" '/green/ {print $3/1}
2,147
Posted By ripat
This regex seems to also return the required...
This regex seems to also return the required output:

grep -o "([^)]\+ [0-9]\{4\})" file

But it will fail on the citations spread on multiple lines as in:


Suggestion, first get rid of all...
1,439
Posted By ripat
Try this: '{a[$0]++} END {for (i in a) if...
Try this:

'{a[$0]++} END {for (i in a) if (a[i]>=2) print i}' file
2,247
Posted By ripat
Yes. Just change your FS as FS="[ |:|@||\t+]"; ...
Yes. Just change your FS as FS="[ |:|@||\t+]";



Usually you can avoid piping a grep result into aw by just using the awk condition filtering like in /string to capture/{... awk processing...}
...
1,790
Posted By ripat
Nice trick for the reverse order! Edit: My...
Nice trick for the reverse order!

Edit:
My solution above does not return the expected result on large dictionaries. The w array gets out of sequence. Updated version inspired by Scrutinizer's...
1,790
Posted By ripat
For the reverse order, just pipe the output in...
For the reverse order, just pipe the output in tac:

awk '{w[length] = w[length] ? w[length]"\n"$0 : $0} END {for(l in w) print w[l]}' file | tac

length() is a awk function that output the,...
1,790
Posted By ripat
awk oneliner alternative awk '{w[length] =...
awk oneliner alternative

awk '{w[length] = w[length] ? w[length]"\n"$0 : $0} END {for(l in w) print w[l]}' file
2,038
Posted By ripat
Use the %s format and make the difference on...
Use the %s format and make the difference on these values.
966
Posted By ripat
By using Scrutinizer's format in a awk command...
By using Scrutinizer's format in a awk command like:

awk '{$10=sprintf("%018.3f",$10)}1' infile

That assumes that the columns are space separated.

Edit: Ooops. Scrutinizer is lightning fast...
1,054
Posted By ripat
Not exactly. NR is the Number of Records seen so...
Not exactly. NR is the Number of Records seen so far.

A possible solution:
awk 'BEGIN{split("jan_feb_mar_apr_may_jun_jul_aug_sep_oct_nov_dec",a,/_/);for (i in a) m[a[i]]=i}{print m[$1],$2,$3'}'...
3,717
Posted By ripat
Start with this: awk -F"[. ]"...
Start with this:

awk -F"[. ]" '{t[$11]+=$15}END{for(i in t) printf "%s %s\n",i,t[i]}' infile
9,090
Posted By ripat
Something like this? awk...
Something like this?
awk '/^Content-Type.+plain/{f=1;getline}/^--/{f=0}/^(Subject|From)/||f{print}' infile
Showing results 1 to 25 of 29

 

Featured Tech Videos

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