String manipulation in bash shell
I am using a script to move a particular file from one location to another location, which retrieves that file name from a log file. When I run this command in the shell prompt, it's okay.
Example: When I run this command:
tail -2 /pretupsvar/pretups_weblogs/DirectPayOutErrorLog.log |
grep 'MESSAGE: SQL Exception:Invalid column index' |
sed 's/.*FILE NAME: //;s/].*//;s/ /\\ /g'
the output is :
userList1305816669650_PB_PBZONE_DLMP_RLMP_ETOPUP_WEEL\ ONE\ PAYOUT.xls
However, when I run this command:
cp `tail -2 /pretupsvar/pretups_weblogs/DirectPayOutErrorLog.log |
grep 'MESSAGE: SQL Exception:Invalid column index' |
sed 's/.*FILE NAME: //;s/].*//;s/ /\\ /g'` /pretupshome/
the output is:
cp: cannot stat `userList1305816669650_PB_PBZONE_DLMP_RLMP_ETOPUP_WEEL':
No such file or directory
cp: cannot stat `ONE': No such file or directory
cp: cannot stat `PAYOUT.xls': No such file or directory
Actually, I do the same in script which is like:
fname=`tail -2 /pretupsvar/pretups_weblogs/DirectPayOutErrorLog.log |
grep 'MESSAGE: SQL Exception:Invalid column index' |
sed 's/.*FILE NAME: //;s/].*//;s/ /\\ /g'`
mv /pretupsvar/pretups_weblogs/BulkComissionPayout/UploadOffline/$fname
/pretupsvar/pretups_weblogs/BulkComissionPayo开发者_如何学Pythonut/Errorfile/
But it can not move this file, showing the same error in above.
Kindly help me: how can I move the same in a script?
Try out putting it inside quotes:
fname=`tail -2 /pretupsvar/pretups_weblogs/DirectPayOutErrorLog.log |
grep 'MESSAGE: SQL Exception:Invalid column index' |
sed 's/.*FILE NAME: //;s/].*//'`
mv "/pretupsvar/pretups_weblogs/BulkComissionPayout/UploadOffline/$fname"
/pretupsvar/pretups_weblogs/BulkComissionPayout/Errorfile/
The path /pretupsvar/pretups_weblogs/BulkComissionPayout/UploadOffline/$fname
has spaces when resolved.
I think putting this statement inside quotes should work.
I think you should not do the space replacement (s/ /\\ /g
) if you want to execute your command this way.
精彩评论