开发者

Bash script to append dynamic file path to existing .ini file possibly using sed?

开发者 https://www.devze.com 2022-12-28 12:43 出处:网络
i have a commonly named .sqlite file contained within many unique user\'s home folders with file structure: /home/user/unique-ip-address/folder/file.sqlite I\'ve decided to move all of these .sqlite f

i have a commonly named .sqlite file contained within many unique user's home folders with file structure: /home/user/unique-ip-address/folder/file.sqlite I've decided to move all of these .sqlite files to a tmpfs mount and have already done so maintaining the full directory structure, so each .sqlite file is now in: /mnt/tmpfs/home/user/unique-ip-address/folder/file.sqlite

I'm looking for a way to edit a commonly named .ini file in each users home folder with a unique file path (ex: /home/user/unique-ip-address/folder/file.ini), i figure using find and sed should do the trick but i'm not sure how as the find results need to match 开发者_C百科the user to the correct folder in /mnt/tmpfs. I would like to append the new .sqlite location used in /dev/shm to file.ini in their home folders after dir= in the file.ini. Thanks!


I believe something like this should do the trick:

find /home/*/unique-ip-address/folder/file.ini | xargs -n1 perl -pe 'BEGIN{$infile="/mnt/tmpfs/$ARGV[0]"} {s/dir=/$&$infile/}'

That command doesn't change anything, it just prints out everything. If it looks like it does what you want, just add a -i.bak to the very end and it will make the changes in place. The original file will be renamed to file.ini.bak.

find /home/*/unique-ip-address/folder/file.ini | xargs -n1 perl -pe 'BEGIN{$infile="/mnt/tmpfs/$ARGV[0]"} {s/dir=/$&$infile/} -i.bak'

0

精彩评论

暂无评论...
验证码 换一张
取 消