Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recent content by jdhahbi

  1. jdhahbi

    grep exact pattern

    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...
  2. jdhahbi

    create new lines

    thank you so much, PHV
  3. jdhahbi

    create new lines

    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
  4. jdhahbi

    create new lines

    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
  5. jdhahbi

    create new lines

    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...
  6. jdhahbi

    how to print line mathing a pattern and line immediately above it

    Hi how to print line matching a pattern and line immediately above it? thanks joseph
  7. jdhahbi

    shorter script using ||

    Hi Feherke thank you for your help. can you specify filed #1 with grep? joseph
  8. jdhahbi

    shorter script using ||

    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
  9. jdhahbi

    compare 2 files and print the common content of file1

    thank you for your help. Joseph
  10. jdhahbi

    compare 2 files and print the common content of file1

    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
  11. jdhahbi

    average of duplicates

    Hi p5wizard This is more complicated than I thought. The problem is that the number of digits vary widely from line to line in my file.
  12. jdhahbi

    average of duplicates

    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
  13. jdhahbi

    average of duplicates

    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
  14. jdhahbi

    average of duplicates

    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...
  15. jdhahbi

    average of duplicates

    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.

Part and Inventory Search

Back
Top