scripting

Find and replace in shell scripting

只愿长相守 提交于 2019-12-31 10:01:47
问题 Is it possible to search in a file using shell and then replace a value? When I install a service I would like to be able to search out a variable in a config file and then replace/insert my own settings in that value. 回答1: Sure, you can do this using sed or awk. sed example: sed -i 's/Andrew/James/g' /home/oleksandr/names.txt 回答2: You can use sed to perform search/replace. I usually do this from a bash shell script, and move the original file containing values to be substituted to a new name

How do you use PowerShell? [closed]

为君一笑 提交于 2019-12-31 08:08:17
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 10 months ago . Windows PowerShell came out last year and got great reviews from many .net bloggers (Hanselman comes to mind). It seemed to be touted as a great new utility that somehow made everything that you would ever do on the command line easier, and integrated with .Net. However,

How does a Linux/Unix Bash script know its own PID?

☆樱花仙子☆ 提交于 2019-12-31 07:58:09
问题 I have a script in Bash called Script.sh , and it needs to know its own PID (i.e. I need to get PID inside the Script.sh ) Any idea how to do this ? 回答1: The variable '$$' contains the PID. 回答2: use $BASHPID or $$ See the manual for more information, including differences between the two. TL;DRTFM $$ Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the invoking shell, not the subshell. $BASHPID Expands to the process ID of the current Bash process. In

How does a Linux/Unix Bash script know its own PID?

狂风中的少年 提交于 2019-12-31 07:58:04
问题 I have a script in Bash called Script.sh , and it needs to know its own PID (i.e. I need to get PID inside the Script.sh ) Any idea how to do this ? 回答1: The variable '$$' contains the PID. 回答2: use $BASHPID or $$ See the manual for more information, including differences between the two. TL;DRTFM $$ Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the invoking shell, not the subshell. $BASHPID Expands to the process ID of the current Bash process. In

Why does combining PDFs make filesize balloon?

若如初见. 提交于 2019-12-31 07:32:13
问题 I'm attempting to strip together various PDFs. They're not that text heavy, with the occasional image. Say for example I have two PDFs, 1.4Mb and 740kb - when I combine them they balloon to 6Mb! I've tried scripted combination, and hand appending, with the same result, so I'm guessing it's an underlying issue. Some explanation of why it happens would be useful, so I can look at ways of avoiding it. Is it a mismatch in colour models? They fonts are minimal. 回答1: You aren't telling us how you

how to use batch file variable outside inner for loop

ε祈祈猫儿з 提交于 2019-12-31 05:37:24
问题 I am not familiar with batch script variable scoping. But I ran into scoping problem due to my lack of batch script experience. for /f %%i in ('dir /s /b "%FolderLocation%"') do ( set fullpathandfilename=%%i :: For %%A in ("%fullpathandfilename%") do ( Set File=%%~nxA echo %%File :: this would work and print out only filename ) echo %File% ::this will not have filename I extracted above ) So how can i use %%File outside my inner for loop 回答1: Again, EnableDelayedExpansion : setlocal

bash only email if occurrence since last alert

我们两清 提交于 2019-12-31 05:36:47
问题 I'm monitoring a log file for a specific word and using tac to output the 5 lines before and after it #!/bin/bash tac /var/log/syslog |grep -m1 -A5 -B5 'WORD' | tac >> /tmp/systemp mailx email commands rm /tmp/systemp and I've setup a cron to run every 5 minutes however as expected I receive duplicate alert emails, how do I make it send an email for the last occurrence and not again until the next one? ie Feb 27 15:05:39 WORD (email) Cron runs again after 5 minutes Feb 27 15:05:39 WORD (don't

Add Image component to new gameobject

独自空忆成欢 提交于 2019-12-31 05:27:49
问题 I created a new game object: GameObject newObject = new GameObject("ObjectName"); newObject.AddComponent<RectTransform>(); newObject.GetComponent<RectTransform>().sizeDelta = new Vector2(width, height); I'm looking for a way to add an image (script) for color purposes. How can I do it? 回答1: The same way you are adding RectTransform. newObject.AddComponent<Image>(); You also need to add using UnityEngine.UI to be able to find the Image component. 回答2: This adds the Image component to your

Add Headers and Footers to Word Document with Power Shell

夙愿已清 提交于 2019-12-31 05:15:43
问题 I am looking for a way to insert headers and footers into a Microsoft Word document that was generated from within Power Shell. Is there a way to do this? If so, what is an example of some code needed to accomplish this? 回答1: # Create a new Word application COM object $Word = New-Object -ComObject Word.Application; # Make the Word application visible $Word.Visible = $true; # Add a new document to the application $Doc = $Word.Documents.Add(); # Get the first Section of the Document object

Add Headers and Footers to Word Document with Power Shell

柔情痞子 提交于 2019-12-31 05:15:10
问题 I am looking for a way to insert headers and footers into a Microsoft Word document that was generated from within Power Shell. Is there a way to do this? If so, what is an example of some code needed to accomplish this? 回答1: # Create a new Word application COM object $Word = New-Object -ComObject Word.Application; # Make the Word application visible $Word.Visible = $true; # Add a new document to the application $Doc = $Word.Documents.Add(); # Get the first Section of the Document object