quoting

Can awk deal with CSV file that contains comma inside a quoted field?

这一生的挚爱 提交于 2019-11-30 10:55:28
I am using awk to perform counting the sum of one column in the csv file. The data format is something like: id, name, value 1, foo, 17 2, bar, 76 3, "I am the, question", 99 I was using this awk script to count the sum: awk -F, '{sum+=$3} END {print sum}' Some of the value in name field contains comma and this break my awk script. My question is: can awk solve this problem? If yes, and how can I do that? Thank you. you write a function in awk like below: $ awk 'func isnum(x){return(x==x+0)}BEGIN{print isnum("hello"),isnum("-42")}' 0 1 you can incorporate in your script this function and check

Sed gives: sed: can't read : No such file or directory

放肆的年华 提交于 2019-11-30 08:05:43
I have the following bash script which repeats for each image found. It needs to iterated over all html , css and js files, and replace all occurrences of an image within that file. for image in app/www/images-theme-dark/*.png do echo "installing icon" $image # extract filename from iconpath iconfile=$(basename $image) iconPath="images/"$(basename $image) # replace paths in all files containing icon paths find app/www -type f \( -name "*.html" -or -name "*.css" -or -name "*.js" \ -or -name "*.appcache" \) \ -exec sed -i '' -e 's|$iconPath|images-theme-dark/$iconfile|g' "{}" \; done However

Can awk deal with CSV file that contains comma inside a quoted field?

余生颓废 提交于 2019-11-29 16:10:27
问题 I am using awk to perform counting the sum of one column in the csv file. The data format is something like: id, name, value 1, foo, 17 2, bar, 76 3, "I am the, question", 99 I was using this awk script to count the sum: awk -F, '{sum+=$3} END {print sum}' Some of the value in name field contains comma and this break my awk script. My question is: can awk solve this problem? If yes, and how can I do that? Thank you. 回答1: you write a function in awk like below: $ awk 'func isnum(x){return(x==x

Escaping quotes when using SSH

*爱你&永不变心* 提交于 2019-11-29 10:26:48
I'm trying to build a simple deployment script for my PHP apps. I know there are several tools for this job (Capistrano, Phing, etc.) but they seem like a lot of work for my simple deployment routine. I use sshpass to avoid typing my password over and over again. But after uploading my compressed installer, I need to ssh into the server and run some commands. One of which is sed. So, quotes are breaking my script. It's something like this: sshpass -p foo ssh user@host " cd /www/htdocs/foo/bar echo 'Untar and remove installer' tar -zxf install.tar.gz sed "s/define('ENVIRONMENT', 'development');

Setting Public Property Values on the Command Line

大兔子大兔子 提交于 2019-11-29 08:10:39
Setting Public Property Values on the Command Line of an msi follows the pattern MyInstaller.msi PUBLICPROPERTY="someValue" This works on "Command Prompt" aka cmd.exe and powershell. But MyInstaller.msi PUBLICPROPERTY="" does not work like expected in powershell. I expected that it sets PUBLICPROPERTY to null but it sets PUBLICPROPERTY to the value "CURRENTDIRECTORY="C:\temp\msi\"" (it does work like expected with cmd.exe). Why do powershell and cmd.exe behaviour different, and how can it be fixed? PowerShell, on Windows of necessity, performs re-quoting of your arguments behind the scenes.

Sed gives: sed: can't read : No such file or directory

感情迁移 提交于 2019-11-29 05:25:33
问题 I have the following bash script which repeats for each image found. It needs to iterated over all html , css and js files, and replace all occurrences of an image within that file. for image in app/www/images-theme-dark/*.png do echo "installing icon" $image # extract filename from iconpath iconfile=$(basename $image) iconPath="images/"$(basename $image) # replace paths in all files containing icon paths find app/www -type f \( -name "*.html" -or -name "*.css" -or -name "*.js" \ -or -name "*

csv writer in Python with custom quoting

♀尐吖头ヾ 提交于 2019-11-29 03:48:31
I'm looking for a way to define custom quoting with csv.writer in Python. There are 4 built-in ways to qoute values: csv.QUOTE_ALL, csv.QUOTE_MINIMAL, csv.QUOTE_NONNUMERIC, csv.QUOTE_NONE However I need a quoting mechanism which will emulate Postgres' FORCE QUOTE * , i.e. it will quote all non-None values. With csv.QUOTE_ALL Python will turn None into '' but I would like to have empty string instead. Is it possible to do that with built-in csv module ( I'm not interested in hacks, I'm already doing that :P )? Or am I forced to write/get some custom csv parser? And generally: is it possible to

Build a JSON string with Bash variables

断了今生、忘了曾经 提交于 2019-11-29 01:08:47
I need to read these bash variables into my JSON string and I am not familiar with bash. any help is appreciated. #!/bin/sh BUCKET_NAME=testbucket OBJECT_NAME=testworkflow-2.0.1.jar TARGET_LOCATION=/opt/test/testworkflow-2.0.1.jar JSON_STRING='{"bucketname":"$BUCKET_NAME"","objectname":"$OBJECT_NAME","targetlocation":"$TARGET_LOCATION"}' echo $JSON_STRING You are better off using a program like jq to generate the JSON, if you don't know ahead of time if the contents of the variables are properly escaped for inclusion in JSON. Otherwise, you will just end up with invalid JSON for your trouble.

How to put double quotes in VS2010 post build step

你。 提交于 2019-11-28 23:19:52
I'm trying to create a post build file copy step in VS2010 which handles path macros when they have embedded spaces. I've tried surrounding the copy commands in double quotes but I get error from when copy is invoked if $(SolutionDir) contains a space. the echoed command line in the error message does not show the double quotes. copy "$(SolutionDir)$(Configuration)\*" "$(TargetDir)" I also tried separately \" and "" but both of these cause the 2 character escape sequence to appear in the echoed command line? How does one properly escape a double quote in a build step? I was having trouble

Using a Variable (PowerShell) inside of a command

六眼飞鱼酱① 提交于 2019-11-28 12:28:39
$computer = gc env:computername # Argument /RU '$computer'\admin isn't working. SchTasks /create /SC Daily /tn "Image Verification" /ST 18:00:00 /TR C:\bdr\ImageVerification\ImageVerification.exe /RU '$computer'\admin /RP password Basically I need to provide the computer name in the scheduled task... Thank you in advance! Single quoted strings will not expand variables in PowerShell. Try a double quoted string e.g.: "$computer\admin" use the command 'hostname' to get the name of the local pc. 来源: https://stackoverflow.com/questions/12393999/using-a-variable-powershell-inside-of-a-command