A way to split a text file into arbitrary blocks based on first column?

0

I have a (very large) text file of the form...

/folder1/fileA
/folder1/fileB
/folder1/fileC
...
/folder999/fileA
/folder999/fileB
/folder999/fileC
...etc

with an unknown number of entries for each folder, and the folder numbers are not necessarily successive. What I'd like to eventually extract is another list telling me the folders that are shown in this file, e.g.

folder1
folder7   
folder76
...etc

but I can't seem to figure out what combination of sed, awk or general script would be able to tell me this.

If anyone has any ideas, they'd be greatly appreciated.

J I

Posted 2015-12-23T00:46:42.073

Reputation: 3

Answers

0

You can use cut:

cut -d/ -f2 verylarge.txt | sort -u
  • -d defines the coulmn delimiter

  • sort -u unifies the list, i.e. each folder is listed just once.

choroba

Posted 2015-12-23T00:46:42.073

Reputation: 14 741