Hi
I am using grep to extract a certain pattern in the example files below. How do I extract pattern 'T1' and not 'T123'?
cat pattern
id
T1
T23
T55
cat file
id name length
T5 Lypla1 2433
T55 sea3 2668
T123 Tmea1 2671
T23 nrea1 2564
T1 mea1 250
T10 mrty1 22
grep -f pattern file
id name...
how can I get the reverse format?
For the lines that have the same first field, I want to reduce them to one line having the second field strings separated by a comma.
inFile
A[tab]x
B[tab]y
B[tab]z
C[tab]r
C[tab]s
C[tab]t
D[tab]q
outFile
A[tab]x
B[tab]y,z
C[tab]r,s,t
D[tab]q
thank you
joseph
thank you everybody. It was very helpful.
I added a tab to get the format I want
awk '{gsub(",","\n\t");print}' inFile.txt
A m
[tab]n
B x
[tab]y
[tab]z
C t
[tab]r
joseph
Hi
I would like to add new lines with the strings after the comma.
The lines in the inFile have 2 fields separated by a tab.
I would like to remove the comma from the 2d fileld and add a new line where the 1st filed is empty and the 2d field is made of the string that followed the comma.
inFile...
Hi
can you please suggest a more elegant, shorter script for printing lines where field #1 is equal to AA or BB or CC …. (sometimes more than 10 values).
awk '$1 == "AA" || $1 == "BB" || $1 == "CC"'
thank you
joseph
Hi
I would like lines from file1 that are common to file2 as in the following example:
cat file1
22 A alp 19 gtein
255 B macr 12 pring
3 C lin 12 pseue
90 D N-ace 8 1
cat file2
B
D
cat outfile
255 B macr 12 pring
90 D N-ace 8 1
thank you for your help
to get 0 decimals, the code should be:
awk 'NR==1{print;next}{n[$1]++;s[$1]+=$2;t[$1]+=$3}END{for(i in n)printf "%s %9.0f %9.0f\n",i,s[i]/n[i],t[i]/n[i]}'
thanks p5wizard
Thank you for your help.
It works fine now, it gives the average with one decimal.
One more request: how can I get the average with no decimals?
Again, I really appreciate your help.
Joseph
I tested the code with the following inFile:
#f1 f2 f2
a 3991037 4155442
a 3993760 4160837
a 3994154 4159990
b 308568 179762
f 3484774 3488370
f 3600005 3666058
outFile:
#f1 f2 f2
a 3992980 4158760
b 308568 179762
f 3542390 3577214
I noticed that the average for a should be 3992984 and not...
Hi
my inFile has 3 fields with duplicates in field1.
I would like to print the average field2 and field3 for the duplicated fild1.
$cat inFile
field1 field2 field3
A 7 2
B 4 2
B 2 3
C 6 5
D 15 2
D 5 3
D 10 4
$cat outFile
field1 field2 field3
A 7 2
B 3 2.5
C 6 5
D 10 3
thank you for your help.
I have 2 sets of data that look like this:
file1:
>s_7_2x1
AAAAAAAAAGTTGGTCTTG
>s_7_24x2
AAAAAAAAGGTCGGGCCTGGTT
>s_7_3x3
AAAAAAACAGAGTTCA
>s_7_4x4
AAAAAAACATGGCGCACTTCTT
>s_7_5x5
AAAAAAACATGGNGCACTTCTTTTCGCNTGGCGGC
file2:
>s_7_2x1
AAAAAAAAAGTTGGTCTTG
>s_7_24x2
AAAAAAAAGGTCGGGCCTGGTT
file2 is a...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.