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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

little trouble I don´t understand 1

Status
Not open for further replies.

malpa

Technical User
Feb 8, 2004
122
CO
Hi,

I have this file
----- temp2.txt ------
carlos,2
carlos,3
carlos,4

omar,2
omar,3
omar,4
omar,5

tom,3
tom,4

I want to transform the previous file, temp2.txt in
--- out.txt----
carlos 2 4
omar 2 5
tom 3 4

My program

awk ' BEGIN{FS=","
getline < "temp2.txt"
cent_in = $1
date_in = $2
close(temp2.txt)
}
{
if(cent_in==$1)
{
cent_in=$1
date_l=$2
}
else if(cent_in!=$1)
{
print cent_in,date_in,date_l
cent_in=$1
date_l=$2
date_in=$2
}
} ' temp2.txt > out.txt

my out.txt

carlos 2 4
omar 2 5
??????????? (what´s going on)

Thanks for your timily assistance.
 
well....... if you could explain the logic behind the 'transform the previous file' - it might be easier to help you.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I think you mean this, but....

nawk -f malpa.awk temp2.txt

malpa.awk:
Code:
BEGIN {
  FS=RS=""
}

{
   split($1, f1, ",")
   split($NF, fl, ",")

   arr[f1[1]] = ( f1[1] in arr) ? arr[f1[1]] OFS f1[2] : f1[2]
   arr[fl[1]] = ( fl[1] in arr) ? arr[fl[1]] OFS fl[2] : fl[2]
}
END {
   for (i in arr)
      print i, arr[i]
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi
This is the orginal file.
----- temp2.txt ------
carlos,2
carlos,3
carlos,4
omar,2
omar,3
omar,4
omar,5
tom,3
tom,4
erick,2

I want to transform the temp2.txt file in a new file. In the new file I could find the name of the people with the ranges found in the second field of the original file temp2.txt.

I don´t know what happen with my program, It doesn´t print the last range.

I want to print out

new out.txt
-----------
carlos, 2-4
omar, 2-5
tom, 3-4


My program doesn´t print the last range. I don´t know why?
 
Code:
BEGIN {
  FS=OFS=","
}

{
  min[$1] = ($1 in min) ? ( min[$1] > $2 ? $2 : min[$1] ) : $2
  max[$1] = ($1 in max) ? ( max[$1] < $2 ? $2 : max[$1] ) : $2
}
END {
   for (i in min)
      print i, min[i] "-" max[i]
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi,

Thank you very much for your timily assistance.
it works fine.

Would you like to explain me what does ? : means ??

Thanks

malpa.
 
Ok, I was reading a manual
That means
conditional expressions
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top