I have a directory on an Ubuntu machine with a large number of files, and subgroups of files starting with the same prefix. I need the list of distinct prefixes present in the name of the directory files, as shown below. For the listing:
pj6_ex_18_i535_tr_92.pdf
pj6_ex_18_i535_tr_95.pdf
...
pj6_ex_14_i535_tr_96.pdf
pj6_ex_14_i535_tr_97.pdf
pj6_ex_14_i535_tr_98.pdf
....
pj1_ex_24_i535_tr_91.pdf
pj1_ex_24_i535_tr_92.pdf
pj1_ex_24_i535_tr_93.pdf
...
pj3_ex_16_i535_tr_23.pdf
pj3_ex_16_i535_tr_22.pdf
I need to get the following list. I imagine that via awk commands it is possible, but I don't know how.
pj6_ex_18_
pj6_ex_14_i535_
pj1_ex_24_i535_
pj3_ex_16_i535_
How can I do this?
pj6_ex_18_
you cut up to 3 hyphens but others 4? typo issue? alsoawk
is not a tool for renaming, don't imagine aboutawk
for this kind of purposes, it's a text-processing tool. – αғsнιη May 05 '21 at 14:03