Is there a simple way to find the longest common prefix of a space-separated list of strings, optionally by field?
For example, given input:
with no field separator, output:
with _ field separator, output:
I have an awk solution which appears to work (although I haven't done much testing):
Searching didn't come up with anything more elegant that could handle both by character and by field. So, just wondering if the forum had any better solutions.
EDIT: The above (cygwin) doesn't seem to work very well on (non-gawk) AIX 6.1. Seems you can't fiddle with NF in END the way I've doing above (although just printing pcount fields of prefix works), and having a blank field separator seems equivalent to whitespace (i.e. it won't split by character).
Last edited by CarloM; 10-25-2013 at 04:45 AM..
Reason: Platforms
Hello Everyone ,
Iam a newbie to shell programming and iam reaching out if anyone can help in this :-
I have two files
1) Insert.txt
2) partition_list.txt
insert.txt looks like this :-
insert into emp1 partition (partition_name)
(a1,
b2,
c4,
s6,
d8)
select
a1,
b2,
c4, (2 Replies)
Good day people,
Kindly advice what is the operator/command that I should try out to if I am about to return a list of prefix of my filename with first 6 character.
I understand I could use sed to retrieve the first 6 charter itself.
but i wonder if there is any aix command allow me to loop... (4 Replies)
Hi,
I am entirely new to Unix, need your help to perform certain actions in unix:
Can anyone please tell me how to list the number of files in UNIX with Common prefix name. "I want just the number of files and not the names of files".
Thanks (12 Replies)
I have a file say "example.xml" and the contents of this example.xml are
<project name="platform/packages/wallpapers/Basic" path="packages/wallpapers/Basic" revision="225e410f054c4ad5c828b0fec9be1b47c4376711"/>
<project name="platform/packages/wallpapers/Galaxy4"... (3 Replies)
Hi all,
I'd like you to help or give any advise about the following:
I have two (2) files, file1 and file2, both files have information common to each other. The contents of file1 is a subset of the contents of file2:
file1:
errormsgadmin
esdp
esgservices
esignipa
iprice
ipvpn
irm... (18 Replies)
Hi all,
I'd like you to help or give any advise about the following:
I have two (2) files, file1 and file2, both files have information common to each other. The contents of file1 is a subset of the contents of file2:
file1:
errormsgadmin
esdp
esgservices
esignipa
iprice
ipvpn
irm... (0 Replies)
Hi ,
I have a text file in the format
DB2:
DB2:
WB:
WB:
WB:
WB:
and a second text file of the format
Time=00:00:00.473
Time=00:00:00.436
Time=00:00:00.016
Time=00:00:00.027
Time=00:00:00.471
Time=00:00:00.436
the last string in both the text files is of the... (4 Replies)
Hi ,
I want to write a simple script.
I have two files
file1:
BCSpeciality
Backend
CB
CBAPQualDisp
CBCimsVFTRCK
CBDSNQualDisp
CBDefault
CBDisney
CBFaxMCGen
CBMCGeneral
CBMCQualDisp
file2:
CSpeciality
Backend (8 Replies)
Thank you for assisting,
I've got a partial solution just needs a tweak.
Hulk-BASH$ cat somefile.txt
oh there is some stuff here
some more stuff here
START_LABEL
stuff I want
more stuff I want
END_LABEL
other stuff here too
and even more stuff here too
Hulk-BASH$
Hulk-BASH$ sed... (8 Replies)