Visit Our UNIX and Linux User Community

Search Results

Search: Posts Made By: ripat
26,702
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...
30,154
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,656
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,656
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 =...
1,207
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,207
Posted By ripat
Another way: awk...
Another way:

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

Useless use of cat and awk instead of head.
1,696
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
...
7,643
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? ^_^
671
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
2,178
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,550
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,447
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,447
Posted By ripat
Try this: awk -F"|" '/green/ {print...
Try this:

awk -F"|" '/green/ {print $3/1}
2,361
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,621
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,438
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...}
...
2,245
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...
2,245
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,...
2,245
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,268
Posted By ripat
Use the %s format and make the difference on...
Use the %s format and make the difference on these values.
1,078
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,183
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,780
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,662
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 03:54 PM.
Unix & Linux Forums Content Copyright 1993-2021. All Rights Reserved.
Privacy Policy