Search Results

Search: Posts Made By: ripat
99,275
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...
8,535
Posted By ripat
Indeed. Corrected version: awk -F','...
Indeed. Corrected version:

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

Merci.
34,539
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,927
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,927
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,651
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,651
Posted By ripat
Another way: awk...
Another way:

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

Useless use of cat and awk instead of head.
10,017
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? ^_^
2,385
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
...
882
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
3,095
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)}}'
3,068
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"
4,294
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.
4,294
Posted By ripat
Try this: awk -F"|" '/green/ {print...
Try this:

awk -F"|" '/green/ {print $3/1}
2,948
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,979
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
3,011
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...}
...
4,580
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,...
4,580
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...
4,580
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,802
Posted By ripat
Use the %s format and make the difference on...
Use the %s format and make the difference on these values.
1,337
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,509
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
297,091
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

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