you mean you're actually writing a shellscript to parse a text file or something bro ? ....Originally posted by sohguanh:Sorry no response in IT Support and Tech Corner forum so come here post. Need help in below.
I have a problem. I need to use Unix uniq command to remove duplicating lines but with an extra twist.
Example
1 apple a
2 apple b
3 orange c
4 orange d
....
I wanna the command to consider the middle field only (i.e apple, orange) to do removing of duplicates. But it seem uniq is treating the whole line to do comparison when remove duplicates. Any idea how?
Dun ask me use M$ Excel as the command is supposed to be in a Unix script to be executed on commandline by data centre operators in a Unix environment.
TIA
Originally posted by sohguanh:yes, that's what I meant, if you're just parsing a simple text file then you can filter out all the unneccessary bits then pipe the output to uniq ... and frankly, i don't think there's much difference performance wise ....
[b]if it's a shellscript you're writing, you can try parsing the middle field with regular expressions, then work on from there ...
Do you mean by first parsing the middle field and then do the uniq command? I wan performance and hence I tot of using juz a single uniq command to do it. If all fails I guess I must use two commands and pipe them together.[/b]
Originally posted by sohguanh:so you just want the middle token eh ? ...
[b]and yes, it filters out the first token ....
Correct but what I want is to filter out the first and the third token when doing comparison. So "1 apple a" should be same as "2 apple b"[/b]
Originally posted by sohguanh:i did it on my apple terminal and it works ....
[b]"uniq -f 1 [input file] | uniq -f 3 " .....
Errrr.... do you actually execute those commands you recommend? Do you have a linux or unix accessible to you? I tried yours and it does not work. I will try to post my working solution later assuming I do in two or more commands[/b]
awk -F " " '{print $1" "$3" "$2;}' a.txt|uniq -f 2| \
awk -F " " '{print $1" "$3" "$2;}'
Originally posted by sohguanh:okay cause i got an INI file which requires me to map specfic values to user defined ranges similarly above
[b]given a certain string [11to200]
how can i grab out the 11 and 200 to do a comparision based on a certain value being passed in ??
You should give an example of what is the input and what you want the output to look like. Then it is clearer cuz by describing in english sentence sometimes ppl can misinterpret especially for english lousy ppl like me[/b]