Matching Pattern & needed desired Output
Hi,
I have below pattern ABCD 1-2-3-4 EFGH 5-6-7-8 ABCD 8-7-4-9 IJKL 9-3-2-5 EFGH 6-9-3-6 IJKL 8-5-9-3 ---- ------- Now output is needed like ABCD : 1-2-3-4,8-7-4-9 EFGH : 5-6-7-8,6-9-3-6 IJKL : 9-3-2-5,8-5-9-3 I am working on TCL script. If solotion is in TCL then much benificial for me. Thanks in advance. |
sorry, my tcl is rusty but hopefully this quick-and-dirty bash will help:
Code:
awk '{print $1}' sumit.txt | sort | uniq > sumit.key |
Hi schneidz,
This help is simply awesome.By going line to line definitely I am finding my desired Pattern. Could you please help me to understand * point in your code awk '{print $1}' sumit.txt | sort | uniq > sumit.key ---->> This provide sorted and unique value(I understand) for key in `cat sumit.key` ------> Taking unique value of first column (I understand) do echo $key : `grep $key sumit.txt` --> *What is role of echo $key : as i know 'grep $key sumit.txt' gets patterns matching. done | sed s/" "//g | sed s/:,/:/ > sumit.out So if i understand this logic about "echo $key : "I will convert this into TCL. Using of sumit.txt & sumit.key is really attractive :). Thanks Sumit Sharma |
Humm, I think I could bang something out in Python quickly, but I'm no good in TCL. Python's bult-in data type "dictionary" looks like a quick solution to this problem. If you must use TCL you might try a TCL forum.
|
On my system, schneidz's code gives this output
Code:
ABCD:ABCD1-2-3-4ABCD8-7-4-9 I tweaked it thus Code:
awk '{print $1}' sumit.txt | sort | uniq > sumit.key Code:
ABCD : 1-2-3-4,8-7-4-9 |
Solved
Simply Osm ....Thanks chrism01 & schneidz. No doubt you both have solved my problem in easy manner. I am trying to convert this into TCL otherwise my last option is to embedded given shell code with my TCL script.
@TheLexx , I am looking for TCL forum here if possible please provide me link for any suitable. Anyways Thanks you Guys ...I will look for more post |
All times are GMT -5. The time now is 01:53 AM. |