Abhay Hegde
Abhay Hegde

Reputation: 1

Removing white spaces within a file name after a specific text using sed

I have few files, having files name in the below form:

export_<directory_name>_system.indexes .json 

Here the directory keeps changing,so it could be anything

However _system.indexes is constant

Notice the space between 'indexes and '.json'.

I want to get rid of the space in between them, so the expected file name is as below

export_<directory_name>_system.indexes.json

I have tried the below:

echo export_direcotoryName_system.indexes .json | sed 's/\s\+//'

All though it does remove the space..but it also removes space from other files which i do not want.

How can restrict the removal only to files having system.indexes in their filenames

Upvotes: 0

Views: 41

Answers (1)

Cyrus
Cyrus

Reputation: 88829

With prename:

prename -n 's/system.indexes .json/system.indexes.json/' *.json

if everythink looks fine, remove -n.

Upvotes: 1

Related Questions