Search Results

Search: Posts Made By: genehunter
Forum: Programming 09-19-2018
2,888
Posted By RudiC
The sample you posted earlier seems to have a...
The sample you posted earlier seems to have a header line. And DOS line terminators (<CR> = \015 = 0x0D = \r = ^M). Try
awk -F "\t" '
{sub ("\r","")
}
NR == 1 {N = split ($0, HD);...
Forum: Programming 09-19-2018
2,888
Posted By RudiC
How about awk -F "\t" ' {for (N=1;...
How about

awk -F "\t" '
{for (N=1; N<=NF; N++) if ($N!="") CNT[N]++}
END {for (N=1; N<=NF; N++) print "col" N ":", CNT[N]
}
' /tmp/ex.txt
col1: 10
col2: 10
col3: 10...
1,873
Posted By RudiC
Neither ... nor. The $1 = $1 trick replaces ALL...
Neither ... nor. The $1 = $1 trick replaces ALL field separators (multiples as well) with the OFS char without modifying the fields' contents. man awk:
1,873
Posted By RudiC
While rdrtx1's proposal works fine for the...
While rdrtx1's proposal works fine for the samples given, it doesn't for the duplicates mentioned as the samples don't have any. Nor is the request for <TAB> field separators in the result fulfilled....
1,254
Posted By Don Cragun
That will work with some versions of awk and give...
That will work with some versions of awk and give you a syntax error with other versions of awk. The following should work with almost any version of awk:
awk '{$1=$1; print>("file"NF)}'...
3,157
Posted By Don Cragun
Yoda gave you directions on how to turn off color...
Yoda gave you directions on how to turn off color for a particular invocation of ls (assuming that you're using a Linux system).

To turn it off permanently for future invocations of ls, we need to...
3,157
Posted By Yoda
Can switch off color and try: ls --color=never
Can switch off color and try:
ls --color=never
7,192
Posted By Don Cragun
Try: awk 'NR==FNR {d[$0];next} ! ($0 in d)...
Try:
awk 'NR==FNR {d[$0];next} ! ($0 in d) {print}' fileB.txt fileA.txt
1,927
Posted By Don Cragun
Since the script I gave doesn't know what files...
Since the script I gave doesn't know what files will be passed in as arguments, thels PUR.*won't work in the general case. But, if you change:
awk 'BEGIN {
fc = -1
}
FNR==1 {fc++
}
in the...
1,927
Posted By Don Cragun
The solution provided my mirni seems to work OK...
The solution provided my mirni seems to work OK except that it doesn't print the key at the start of each output line. (It also prints the 0 value as 0.000, but I don't see why that really matters.)...
6,093
Posted By ctsgnb
Sorry but few adding question : Which foo...
Sorry but few adding question :

Which foo entry does NOT need to be displayed :

1. Any foo entry that has his rs# NOT in bar ?
2. Any foo entry that has his [0-9]# NOT in bar ?
3. Any foo...
6,155
Posted By radoulov
Sure, I'll try. The code is: awk 'END...
Sure,
I'll try.

The code is:

awk 'END {
for (i = 0; ++i <= idx;)
printf "%s\n\n", p[i]
if (p[i - 1] != r)
print r
}
/\$newpage/ {
sub(/\n\n*$/, x, r)
t[r]++ ||...
6,155
Posted By radoulov
OK, try this: awk 'END { for (i = 0; ++i...
OK, try this:

awk 'END {
for (i = 0; ++i <= idx;)
printf "%s\n\n", p[i]
if (p[i - 1] != r)
print r
}
/\$newpage/ {
sub(/\n\n*$/, x, r)
t[r]++ || p[++idx] = r
r...
3,317
Posted By agama
Try this: awk ' /ZIP/ {next;} $NF < .05 {...
Try this:


awk ' /ZIP/ {next;} $NF < .05 { printf( "%s %s\n", $0, FILENAME ); }' *.results >new.file


Adds the filename as the right most column to each output line. Does discards the header...
12,814
Posted By Franklin52
awk 'NR==FNR{s=$1; sub(".*"$2,"");a[s]=$0; next}...
awk 'NR==FNR{s=$1; sub(".*"$2,"");a[s]=$0; next} a[$1]{print $0 a[$1]} ' bar.txt foo.txt

Explanation:
NR==FNR

If we read the first file.
s=$1

Capture the first field in variable s to use...
8,386
Posted By Franklin52
Or: awk 'NR==1{print;next} $5=="ADD"{print |...
Or:
awk 'NR==1{print;next} $5=="ADD"{print | "sort -grk9"}' OFS="\t" file
8,386
Posted By vgersh99
nawk 'FNR==1{print >out;next}$5=="ADD" {print...
nawk 'FNR==1{print >out;next}$5=="ADD" {print $0}' OFS='\t' out=Assoc_sorted.TXT Assoc.txt |sort -gk9 >>Assoc_sorted.TXT
49,606
Posted By radoulov
Yes, in this case the number of arguments...
Yes,
in this case the number of arguments (input files) is limited only by your system (MAX_ARGS kernel limit).

As far as the script is concerned, the filenames are irrelevant,
just pass the...
49,606
Posted By radoulov
Just to clarify that I wrote all that code only...
Just to clarify that I wrote all that code only because of this requirement:




:)
49,606
Posted By radoulov
Given your sample data, the following script: ...
Given your sample data, the following script:

awk 'END {
for (R in rec) {
n = split(rec[R], t, "/")
if (n > 1)
dup[n] = dup[n] ? dup[n] RS sprintf("\t%-20s -->\t%s", rec[R],...
3,302
Posted By Scrutinizer
Indeed, that was the only issue: $ awk...
Indeed, that was the only issue:
$ awk 'NR==FNR{A[$2]=$3;next} $2=A[$1]' OFS="\t" bar foo
451 volkswagen
3,302
Posted By vgersh99
awk 'NR==FNR{a[$0];next} $2 in a {print $2,$4}'...
awk 'NR==FNR{a[$0];next} $2 in a {print $2,$4}' OFS='\t' foo bar > barfoo
2,869
Posted By jim mcnamara
It is a problem with tty settings - how bash...
It is a problem with tty settings - how bash reads keystrokes from the terminal.

Look for the word "erase" followed by some goofy character(s) in the output of:

stty -a


You want that to be...
12,182
Posted By a_programmer
You use wrappers when you want to enhance the...
You use wrappers when you want to enhance the functionality of an existing utility/command without changing it (usually for backwards compatibility or because you don't have access to the original...
11,435
Posted By Scrutinizer
If your ranges get bigger, then it as an...
If your ranges get bigger, then it as an alternative to egrep you can use anbu's solution provided your input file is numerically sorted on the first column, e.g.:awk '$1 == 21, $1 == 25; $1 == 101,...
Showing results 1 to 25 of 30

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