Search Results

Search: Posts Made By: verse123
1,324
Posted By Don Cragun
If you wanted to combine all of your input files...
If you wanted to combine all of your input files (with names ending in ".1" as in the 1st message in this thread) into a single output file (keeping the heading only from the 1st file), you could...
1,324
Posted By Akshay Hegde
$ awk '{s = FNR==1 ? "\"""name""\"" :...
$ awk '{s = FNR==1 ? "\"""name""\"" : "\""FILENAME"\"" ; print s,$0}' OFS=',' infile >outfile

for multiple try

$ awk 'FNR==1{if(f)close(f);f="Newfile_"FILENAME}{s = FNR==1 ? "\"""name""\"" :...
1,056
Posted By Don Cragun
This seems a little bit simpler to me: awk ' ...
This seems a little bit simpler to me:
awk '
{ while(length($2) >= 5) {
print $1, substr($2, 1, 5)
$2 = substr($2, 6)
}
}' input_filewhich produces the output:
DOG abcde
DOG fghij
CAT...
2,714
Posted By Don Cragun
By definition, if there are an odd number of...
By definition, if there are an odd number of elements in a list, the median is the middle element in the (sorted) list. (So for dog, with the values in the 3rd field being 0, 3, and 4; 3 is the...
2,714
Posted By Don Cragun
You could try something like: #!/bin/ksh ...
You could try something like:
#!/bin/ksh
IAm=${0##*/} # Save basename of the current script.
tempf="$IAm.$$" # Set temp filename to be used by sort.

awk -v debug="$debug" -v tempf="$tempf" '
#...
2,366
Posted By Scrutinizer
Yet one more: awk ' /^%/{ i=$1 ...
Yet one more:
awk '
/^%/{
i=$1
getline s
A[i]=(i in A)?substr(s, length(s)-8) substr(A[i],1,9):s
}
END{
for (i in A) {
print i
print A[i]
}
}
'...
2,366
Posted By MadeInGermany
Another one awk ' $1~/^%/ { key=$1 ...
Another one

awk '
$1~/^%/ {
key=$1
next
}
{
if (key in s1) {
s2[key]=substr($0,length($0)-8)
} else {
s1[key]=substr($0,1,9)
}
}...
2,366
Posted By Yoda
An awk solution: awk ' { ...
An awk solution:
awk '
{
if ( $1 ~ /^%/ )
{
A[$1]++
i = $1
}
else
...
1,704
Posted By Scrutinizer
Oops, did not have a chance to test it. Made a...
Oops, did not have a chance to test it. Made a correction to my post.
1,704
Posted By Scrutinizer
Try: while read A B do mawk -v...
Try:
while read A B
do
mawk -v a="$A" 'NR>1{D[$1]+=gsub(a,x,$2); F[$1]++}; END{for (i in D) print i,D[i],F[i]}' file2 > $A.out
done < file1
1,741
Posted By Scrutinizer
The general solution in #8 should be useable, but...
The general solution in #8 should be useable, but it would be better to use code grouping {} instead of a new subshell () for every iteration..

for/while something
do
{
code segment
...
1,741
Posted By Chubler_XL
You want something more like this then: ...
You want something more like this then:

while read A B
do
((i++))
awk '{if(NR == FNR) {a[$0]} else {for (x in a) {if($0 ~ x) {print $0; next}}}}' file2 file1 > $i.out
done
1,741
Posted By Chubler_XL
Is something like this what your after: ...
Is something like this what your after:

while read A B
do
( something
something else file1 ) > out_$A
done < file2
1,741
Posted By Scrutinizer
The while loop will call grep three times with a...
The while loop will call grep three times with a grep -v YES a grep -v NO and a grep -v GOOD and that output is concatenated.

Alternatively you could try without a while loop with:
grep -vf file2...
1,741
Posted By SriniShoo
Try the below awk '{if(NR == FNR) {a[$0]} else...
Try the below
awk '{if(NR == FNR) {a[$0]} else {for (x in a) {if($0 ~ x) {print $0; next}}}}' file2 file1
5,910
Posted By Don Cragun
Does this help? #!/bin/ksh awk ' NR > 1 {#...
Does this help?
#!/bin/ksh
awk '
NR > 1 {# For all lines except line 1 (which contains headers; not data), loop
# through the 2nd field and increment the number of times the six
...
5,910
Posted By Don Cragun
With the simple awk program: #!/bin/ksh awk '...
With the simple awk program:
#!/bin/ksh
awk '
NR > 1 {for(i = length($2) - 5; i >= 1; i--)
c[substr($2, i, 6)]++
}
END { for(i in c)
print c[i], i | "sort...
1,704
Posted By Scrutinizer
Try: awk 'NR>1{D[$1]+=gsub(/dog/,x,$2);...
Try:
awk 'NR>1{D[$1]+=gsub(/dog/,x,$2); F[$1]++} END{for (i in D) print i,D[i],F[i]}' file
1,704
Posted By Akshay Hegde
$ cat file ID String EN03...
$ cat file
ID String
EN03 typehellobyedogcatcatdog
EN09 typehellobye
EN08 dogcatcatdog
EN09 catcattypehello
EN10 typehellobyedogcatcatdog
EN10 typehellobyedogcatcatdogdog
awk '
...
1,846
Posted By agama
Assuming that having all of your columns output...
Assuming that having all of your columns output in the same size field works, this is a quick and dirty hack:



awk '
$2 > 30 && $5 == $3 {
for( i = 1; i <= NF; i++ )
...
Showing results 1 to 20 of 20

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