So here is my problem: conceptually I know what how to do it, but I am still learning to script and hence dont quite know actually how to do this efficiently !
Any help with any of these options or a computationally better solution would be appreciated! I looked up quite a few options for one liners in awk, sed and grep etc but they mostly tip on getting common lines between multiple files and such. I am trying to get that one liner to work for contents of the same file across multiple lines. I have implemented option 2 but that is not very elegant, hence the post
I have this file-A with the following contents:
HWI-X00545:36:C1V15ACPX:2:1206:21033:18295
HWI-X00545:36:C1V15ACPX:2:2210:7893:55181
HWI-X00545:36:C1V15ACPX:2:2306:18502:73182
I want to get just the common parts of all the lines in file-A.
option 1: I could count the number of ":" and print everything before the fourth ":" not inclusive of the fourth ":" ( I could not figure how to do that!) and uniq
option 2: I could split lines at ":" and then awk the columns and join. ( this I feel is cumbersome,there must be a better way and easiest would be to option 3)
sed 's/:/\t/g' trial_header.txt | awk '{print $1":"$2":"$3":"$4}' | uniq
HWI-X00545:36:C1V15ACPX:2
option 3: just print the common parts of all lines in file-A and uniq it! ( not sure how to do this either! sort , uniq can work on when all the characters of all lines are same, not when partial lines are same??)
Note: BTW, I cannot do a character count, like cut -c -25 as this works for just this one file. I have other files with varying number of characters before the fourth ":" and I cant put it in a for loop due to that.
Thankyou in advance!
Given that this is a question of the best way to achieve a given task, I have changed the label from forum to question. Forums are for open-ended discussions that likely don't have a definitive answer.
I don't understand your question :
what would be the output for the common parts in
?
That would be the output , and after uniq it would be
HWI-X00545:36:C1V15ACPX:2