Remove Double Value at Latest Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove Double Value at Latest Output
# 1  
Old 01-31-2012
Remove Double Value at Latest Output

Hello all, I have file like this:
input.dat:
Code:
                              3778 10000 25
                              3778 10001 26
                              3778 10002 29
                              3779 10000 30 
                              3779 10010 31 
                              3779 10012 31 
                              3779 10014 33 
                              3779 10014 33 
                              3780 10000 33 
                              3780 10001 33 
                              3780 10002 78 
                              3780 10002 78
                              3781 10000 33
                              3781 10001 78
                              3781 10005 67

I have tried like this:
Code:
echo -n "   min value= "
read minvalue
echo -n "   max value = "
read maxvalue
set counter = 0
set rgbefore = 0
awk '{ 
       { data=$1 }
       {
         if (data==counter)
         { 
           print "                             " ,$2,"= ",$3,"," 
         }
         else
         { 
           if (rgbefore!=0)
           { 
             print "                             " ,"'"$maxvalue"'","= ",rgbefore,"," 
           }
           print "                              DATA" ,data,","
           print "                             " ,"'"$minvalue"'","= ",$3,"," 
           print "                             " ,$2,"= ",$3,"," 
         }
       }
       { counter=data }
       { rgbefore=$3 }
     }' input.dat > output.dat

recent output.dat:
Code:
                              DATA  3778 ,
                              10000 =  25 ,
                              10001 =  26 ,
                              10002 =  29 ,
                              10014 =  29 ,
                              DATA  3778 ,
                              10000 =  30 ,
                              10010 =  31 ,
                              10012 =  31 ,
                              10014 =  33 ,
                              10014 =  33 ,
                              DATA  3778 ,
                              10000 =  33 ,
                              10001 =  33 ,
                              10002 =  78 ,
                              10002 =  78 ,
                              10014 =  78 ,
                              DATA  3778 ,
                              10000 =  33 ,
                              10001 =  78 ,
                              10014 =  67 ,
                              10014 =  67 ,

but, the problem is: when I input maxvalue=10014, I had already gotten SIMILAR VALUE --> look at end of DATA 3778 & DATA 3778.

This is desire output.dat:

Code:
                              DATA  3778 ,
                              10000 =  25 ,
                              10001 =  26 ,
                              10002 =  29 ,
                              10014 =  29 ,
                              DATA  3778 ,
                              10000 =  30 ,
                              10010 =  31 ,
                              10012 =  31 ,
                              10014 =  31 ,
                              DATA  3778 ,
                              10000 =  33 ,
                              10001 =  33 ,
                              10002 =  78 ,
                              10002 =  78 ,
                              10014 =  78 ,
                              DATA  3778 ,
                              10000 =  33 ,
                              10001 =  78 ,
                              10014 =  78 ,

Thanks in advance,
-Attila

Last edited by attila; 01-31-2012 at 10:12 PM..
# 2  
Old 01-31-2012
Code:
#!/bin/bash
echo -n "   min value= "
read minvalue
echo -n "   max value = "
read maxvalue
set counter = 0
set rgbefore = 0
awk '{
       { data=$1 }
       {
         if (data==counter)
         {
           if ( rgbefore != $3 || inbefore != $2 )
           {
           print "                             " ,$2,"= ",$3,","
           }
         }
         else
         {
           if (rgbefore!=0)
           {
             #print "                             " ,"'"$maxvalue"'","= ",rgbefore,","
           }
           if ( rgbefore != $3 || inbefore != $2 )
           {
           print "                              DATA" ,data,","
           #print "                             " ,"'"$minvalue"'","= ",$3,","
           print "                             " ,$2,"= ",$3,","
           }
         }
       }
       { counter=data }
       { rgbefore=$3 }
       { inbefore=$2 }
}' input.dat > output.dat

Input file:
Code:
3778 10000 25
3778 10001 26
3778 10002 29
3779 10000 30
3779 10010 31
3779 10012 31
3779 10014 33
3779 10014 33
3780 10000 33
3780 10001 33
3780 10002 78
3780 10002 78
3781 10000 33
3781 10001 78
3781 10005 67

Output File:
Code:
                              DATA 3778 ,
                              10000 =  25 ,
                              10001 =  26 ,
                              10002 =  29 ,
                              DATA 3779 ,
                              10000 =  30 ,
                              10010 =  31 ,
                              10012 =  31 ,
                              10014 =  33 ,
                              DATA 3780 ,
                              10000 =  33 ,
                              10001 =  33 ,
                              10002 =  78 ,
                              DATA 3781 ,
                              10000 =  33 ,
                              10001 =  78 ,
                              10005 =  67 ,

# 3  
Old 01-31-2012
Hi knight_eon, every of the desire output need "maxvalue" on the latest value. Like this.

Code:
                              DATA  3778 ,
                              10000 =  25 ,
                              10001 =  26 ,
                              10002 =  29 ,
                              10014 =  29 ,
                              DATA  3778 ,
                              10000 =  30 ,
                              10010 =  31 ,
                              10012 =  31 ,
                              10014 =  31 ,
                              DATA  3778 ,
                              10000 =  33 ,
                              10001 =  33 ,
                              10002 =  78 ,
                              10002 =  78 ,
                              10014 =  78 ,
                              DATA  3778 ,
                              10000 =  33 ,
                              10001 =  78 ,
                              10014 =  78 ,


Any idea, please.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

To remove double quotes from specific columns

Hi, I've a requirement like, in a csv file of 30+ fields where all the columns are having double quotes I need to remove the double quotes from certain fields and certain field should remain as it is. Eg:... (6 Replies)
Discussion started by: Krishnanth S
6 Replies

2. Shell Programming and Scripting

Remove double char occurences

I have a file with random characters where every time a char occurs twice, one occurrence must be removed. Eg. asjkdhaSSd Must become: asjkdhaSd Anybody has a SED script in mind to do it? (1 Reply)
Discussion started by: rlopes
1 Replies

3. UNIX for Dummies Questions & Answers

Remove all the subdirectories except latest 5 inside any given directory

I Want to remove all the sub-directories except latest five in any given TGTDIR. Is there a way to do so without making a cd to TGTDIR? I have tried the following but not worked. Thank you. rm -rf `ls -t $TGTDIR | awk 'NR>5'` (20 Replies)
Discussion started by: Devendra Hupri
20 Replies

4. Shell Programming and Scripting

Trying to remove double quotes

Hi, I am little new to forum and new on unix side. I have a small issue below: I am reading a file that has 5 columns something like below. col1,col2,col3,col4,col5 Some records are having double quoted values something like below: "value1","value2","value3","value4","value5" I need... (8 Replies)
Discussion started by: Saanvi1
8 Replies

5. UNIX for Dummies Questions & Answers

Want to remove all lines but not latest 50 lines from a file

Hi, I have a huge file which has Lacs of lines. File system got full. I want your guys help to suggest me a solution so that I can remove all lines from that file but not last 50,000 lines. I want solution which can remove lines from existing file so that I can have some space left with. (28 Replies)
Discussion started by: prashant2507198
28 Replies

6. Shell Programming and Scripting

Remove Duplicates on multiple Key Columns and get the Latest Record from Date/Time Column

Hi Experts , we have a CDC file where we need to get the latest record of the Key columns Key Columns will be CDC_FLAG and SRC_PMTN_I and fetch the latest record from the CDC_PRCS_TS Can we do it with a single awk command. Please help.... (3 Replies)
Discussion started by: vijaykodukula
3 Replies

7. UNIX for Dummies Questions & Answers

Remove two delimiters, space and double quotes

I would like to know how to replace a space delimiter with a ^_ (\037) delimiter and a double quote delimiter while maintaining the spaces inside the double quotes. The double quote delimiter is only used on text fields. I'd prefer a one-liner, but could handle a function or script that accepts... (4 Replies)
Discussion started by: SteveDWin
4 Replies

8. UNIX for Advanced & Expert Users

How to remove a character which is enclosed in Double quotes

I want to remove the comma which is present within the double quoted string. All other commas which is present outside double quotes should be present. Input : a,b,"cc,dd,ee",f,ii,"jj,kk",mmm output : a,b,"ccddee",f,ii,"jjkk",mmm (3 Replies)
Discussion started by: mohan_tuty
3 Replies

9. UNIX for Dummies Questions & Answers

Remove double quotes

A Triva question. What is the easy way to remove the double quotes in the file in the following format. "asdfa","fdgh","qwer" tr -d '\"' <filename >newfilename mv newfilename oldfilename This need to be handled in a script. Any better way to do this. Will sed be more effecient? One... (3 Replies)
Discussion started by: deepakwins
3 Replies

10. Shell Programming and Scripting

Find and remove all but the latest file

Hi, Would appreciate if someone could help me with the following requirement. Say I have a directory where a file called abc_$timestamp.txt is created couple of times in a day. So this directory would have files like abc_2007-03-28-4-5-7.txt abc_2007-03-28-3-5-7.txt... (4 Replies)
Discussion started by: hyennah
4 Replies
Login or Register to Ask a Question