How can I rename all files within a folder with the first word of their content? For example if a.txt contains “Unix is an OS” in its first line then a.txt should be renamed to Unix.txt
Tell me more
×
Unix & Linux Stack Exchange is a question and answer site for
users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
|
|
Try this:
or more long variant (as script):
In case when destination file exists this one-liner skips it. |
|||||
|
|
Here is my approach.
|
||||
|
|
|
Use this oneliner
This will replace all files with the first word in that file + |
|||||
|
|
||||
|
|
|||||
|
|
On your own risk: :)
This works with easy filenames, containing easy words. A file "O'Reilly" containing as first word "Eto'o" will fail. Miserably. |
|||||||||
|