Search Results

Search: Posts Made By: ripat
53,252
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...
7,867
Posted By ripat
Indeed. Corrected version: awk -F','...
Indeed. Corrected version:

awk -F',' 'NR==FNR{_[$0]=1;next}!_[$4]{print}' exclude infile

Merci.
31,158
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,717
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,717
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,292
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,292
Posted By ripat
Another way: awk...
Another way:

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

Useless use of cat and awk instead of head.
8,031
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? ^_^
1,757
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
...
708
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,374
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,672
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,589
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,589
Posted By ripat
Try this: awk -F"|" '/green/ {print...
Try this:

awk -F"|" '/green/ {print $3/1}
2,494
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,703
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,535
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,553
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,553
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,553
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,362
Posted By ripat
Use the %s format and make the difference on...
Use the %s format and make the difference on these values.
1,131
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,231
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'}'...
Forum: Tips and Tutorials 10-08-2006
289,616
Posted By ripat
Simple date and time calulation in BASH
The GNU date command in full of goodies but not when it comes to calculate a date or time difference. Here is what I came up with after looking to more than one solution.

Code should be self...
Showing results 1 to 25 of 29

 

Featured Tech Videos

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