Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Replace space within quotes

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 11-14-2017
Replace space within quotes

i have an output that i receive and it looks like this:

Code:
echo '/var/FTPROOT/px/sci/archive/20171102070057904-DY_DC04_Daily Inventory Sync-en-us.csv' '/var/FTPROOT/px/sci/archive/20171102070058291-DY_DC07_Daily Inventory Sync-en-us.csv'

what i want to do is replace the spaces in the file names with asterisks "*".

end result should be:

Code:
echo '/var/FTPROOT/px/sci/archive/20171102070057904-DY_DC04_Daily*Inventory*Sync-en-us.csv' '/var/FTPROOT/px/sci/archive/20171102070058291-DY_DC07_Daily*Inventory*Sync-en-us.csv'

i tried with this:

Code:
echo '/var/FTPROOT/px/sci/archive/20171102070057904-DY_DC04_Daily Inventory Sync-en-us.csv' '/var/FTPROOT/px/sci/archive/20171102070058291-DY_DC07_Daily Inventory Sync-en-us.csv' | sed 's~ ~*~g'

but of course, this will replace all the spaces with asterisks. which is not what i want. i only want the spaces within the single quotes to be replaced with an asterisk.
# 2  
Old 11-14-2017
Hello SkySmart,

Could you please try following and let me know if this helps.(test with only provided sample).
Code:
echo '/var/FTPROOT/px/sci/archive/20171102070057904-DY_DC04_Daily Inventory Sync-en-us.csv' '/var/FTPROOT/px/sci/archive/20171102070058291-DY_DC07_Daily Inventory Sync-en-us.csv' | awk -v RS=" /" -F"/" '{gsub(/ /,"*",$NF);print}' ORS=" /" OFS="/"
OR
echo '/var/FTPROOT/px/sci/archive/20171102070057904-DY_DC04_Daily Inventory Sync-en-us.csv' '/var/FTPROOT/px/sci/archive/20171102070058291-DY_DC07_Daily Inventory Sync-en-us.csv' |
awk -v RS=" /" -F"/" '{gsub(/ /,"*",$NF);print}' ORS=" /" OFS="/"

Thanks,
R. Singh
The Following User Says Thank You to RavinderSingh13 For This Useful Post:
SkySmart (11-14-2017)
# 3  
Old 11-14-2017
Try:
Code:
echo "'/var/FTPROOT/px/sci/archive/20171102070057904-DY_DC04_Daily Inventory Sync-en-us.csv' '/var/FTPROOT/px/sci/archive/20171102070058291-DY_DC07_Daily Inventory Sync-en-us.csv'" | 
awk '{for(i=2; i<=NF; i+=2) gsub(" ","*",$i)}1' FS=\' OFS=\'

You need the double quotes around the line with the single quoted paths, otherwise the single quotes will be interpreted and removed by the shell and never reach sed or awk.


---
That is, if you need to specify the paths on a single line

Last edited by Scrutinizer; 11-14-2017 at 02:22 AM..
The Following User Says Thank You to Scrutinizer For This Useful Post:
SkySmart (11-14-2017)
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace Double quotes within double quotes in a column with space while loading a CSV file mlavanya Shell Programming and Scripting 6 05-12-2015 12:05 AM
Replace delimeter between quotes with \| using sed or awk BrahmaNaiduA Shell Programming and Scripting 4 05-04-2015 04:55 PM
awk to find and replace Double quotes between pipes krux_rap Shell Programming and Scripting 5 09-16-2014 12:20 AM
Replace newline character between a double quotes to a space ajahuja Shell Programming and Scripting 8 08-02-2012 10:43 AM
Replace a value in the file that start with quotes chandu123 UNIX for Advanced & Expert Users 6 06-26-2012 04:44 PM
Remove two delimiters, space and double quotes SteveDWin UNIX for Dummies Questions & Answers 4 01-11-2012 07:35 PM
How to replace double quotes in to ascii value? rajesh4851 UNIX for Dummies Questions & Answers 4 05-11-2011 03:27 AM
sed replace spaces between quotes with a variable EXT3FSCK Shell Programming and Scripting 3 03-07-2010 12:22 AM
Replace cloud symbol with single quotes pklcnu Linux 4 03-02-2010 02:46 AM
Replace multiple blanks within double quotes jgrogan Shell Programming and Scripting 5 07-14-2008 09:54 AM


All times are GMT -4. The time now is 12:40 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password