Sponsored Content
Full Discussion: Impute values within groups
Top Forums Shell Programming and Scripting Impute values within groups Post 302928531 by MadeInGermany on Friday 12th of December 2014 11:06:28 AM
Old 12-12-2014
Another one, perhaps even more clumsy, but works with any awk (but the Solaris /usr/bin/awk -> oawk)
Code:
awk '
BEGIN {OFS="\t"}
function prlast(){
  f=""
  if (T1=="") {
    t=substr(T2,1,1)
    for (i=1;i<=length(T1T2);i++) {
      s=substr (T1T2,i,1)
      if (s!=t) {
        print p,"T1",s s,"imputed"
        f=s
        break
      }
    }
  }
  if (T2=="") {
    t=substr(T1,1,1)
    for (i=1;i<=length(T1T2);i++) {
      s=substr (T1T2,i,1)
      if (s!=t && s!=f) {
        print p,"T2",s s,"imputed"
        break
      }
    }
  }
}
p!=$1 && NR>2 {
  # next group begins
  prlast()
  T1=T2=T1T2=""
}
{
  if ($2=="T1") T1=T1 $3
  else if ($2=="T2") T2=T2 $3
  else if ($2=="T1*T2") T1T2=T1T2 $3
  p=$1
  print
} END {
  prlast()
}
' file


Last edited by MadeInGermany; 12-12-2014 at 12:12 PM..
This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. AIX

Where are my groups

Hello A couple of weeks ago, I added a user to an AIX 5.3 system. I go to add one today, and it appears that when creating a user in smit, I cannot see any groups. No primary groups No Group set No Admin Groups The /etc/group and etc/secuity/group files seem to be intact. I did... (4 Replies)
Discussion started by: mhenryj
4 Replies

2. Shell Programming and Scripting

groups starting with c2?

I have some groups and when i issue a command like groups $LOGNAME it displays in one line rfautosys c2ru cash2 I want to fetch only group starting with c2 but when i grep i am getting full line. Can someone advise on this please as how i can get output as c2ru? (2 Replies)
Discussion started by: gehlnar
2 Replies

3. Solaris

groups

how to create 1000 users in 1 group (0 Replies)
Discussion started by: tirupathi
0 Replies

4. Solaris

groups

1 user in member of 4 groups find file permissions and default group (1 Reply)
Discussion started by: tirupathi
1 Replies

5. Shell Programming and Scripting

Remove matched values and their related groups

For each value in file1 it has to check in file2 and file3. If value matched it has to delete that value and related group value in file2 and file3. In this example it takes A , deletes A and take related group value 1 and deletes E-1,then checks in file3 and deletes K-1.After that it takes D... (7 Replies)
Discussion started by: kanagaraj
7 Replies

6. HP-UX

Groups access

Hi all, Can someone tell me how I can get around this problem. Basically I use the HP-UX OS and I work with 2 top level directories. /z/group1 /z/group2 these 2 dirs are managed where group1 can only be access by one set of users and group2 another. This is managed by adding the 2... (3 Replies)
Discussion started by: cyberfrog
3 Replies

7. Shell Programming and Scripting

Groups in Unix ???

What is Primary group and Secondary Group in Unix.? (1 Reply)
Discussion started by: gwgreen1
1 Replies

8. UNIX for Dummies Questions & Answers

Groups

Must I be in a group? I am using Ubuntu and am the only user on my PC. I know how to change groups but do not see a way to not be in a group. Any help would be appreciated. (2 Replies)
Discussion started by: nthepines
2 Replies

9. Shell Programming and Scripting

Print values within groups of lines with awk

Hello to all, I'm trying to print the value corresponding to the words A, B, C, D, E. These words could appear sometimes and sometimes not inside each group of lines. Each group of lines begins with "ZYX". My issue with current code is that should print values for 3 groups and only is... (6 Replies)
Discussion started by: Ophiuchus
6 Replies

10. Solaris

Groups is not visible

OS : SunOS 5.8 I am trying to add a user ad3059 to the following groups, A B C D ( four groups A,B,C,D) When i use usermod command and add the user to the above groups, and go to > groups ad3059 other C D It doesnt show A and B groups and shows it as other.Please advice on how... (13 Replies)
Discussion started by: Revathi2089
13 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 04:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy