spaces

Remove empty lines from txtfiles, remove spaces from start and end of line

*爱你&永不变心* 提交于 2019-12-03 08:31:39
问题 Which one would be better: sed -e '/^$/d' *.txt sed 'g/^$/d' -i *.txt Also, how do I remove spaces from beginning and end of each line in the text file? 回答1: $ sed 's/^ *//; s/ *$//; /^$/d' file.txt `s/^ *//` => left trim `s/ *$//` => right trim `/^$/d` => remove empty line 回答2: Even more simple method using awk. cat filename.txt | awk 'NF' | awk '{$1=$1;print}' awk 'NF' - This will remove all blank/empty lines. awk '{$1=$1;print}' - This will remove only trailing white spaces, (both left and

How do I set up Vim autoindentation properly for editing Python files?

送分小仙女□ 提交于 2019-12-03 00:02:46
问题 I've trouble setting up Vim (7.1.xxx) for editing Python files (*.py). Indenting seems to be broken (optimal 4 spaces). I've followed some tutorials I found via Google. Still no effect :/ Please help. 回答1: I use this on my macbook: " configure expanding of tabs for various file types au BufRead,BufNewFile *.py set expandtab au BufRead,BufNewFile *.c set noexpandtab au BufRead,BufNewFile *.h set noexpandtab au BufRead,BufNewFile Makefile* set noexpandtab " -------------------------------------

Read input numbers separated by spaces

醉酒当歌 提交于 2019-12-02 20:41:22
This may be a total beginner's question, but I have yet to find an answer that works for me. Currently, I'm writing a program for a class that takes in a user's input (which can be one or more numbers separated by spaces), then determines whether the number is prime, perfect, or neither. If the number is perfect, then it will display the divisors. Thus far, I've already written the code for the prime, perfect, and listing the divisors. I'm stuck on the input portion of my program. I don't know how to get the input that's separated by spaces to go through my loops one at a time. This is my

Indenting heredocs with spaces [duplicate]

China☆狼群 提交于 2019-12-02 20:13:14
This question already has answers here : here-document gives 'unexpected end of file' error (5 answers) For personal development and projects I work on, we use four spaces instead of tabs. However, I need to use a heredoc, and I can't do so without breaking the indention flow. The only working way to do this I can think of would be this: usage() { cat << ' EOF' | sed -e 's/^ //'; Hello, this is a cool program. This should get unindented. This code should stay indented: something() { echo It works, yo!; } That's all. EOF } Is there a better way to do this? Let me know if this belongs on the

Linux - Replacing spaces in the file names

断了今生、忘了曾经 提交于 2019-12-02 13:53:06
I have a number of files in a folder, and I want to replace every space character in all file names with underscores. How can I achieve this? neesh This should do it: for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done I prefer to use the command 'rename', which takes Perl-style regexes: rename "s/ /_/g" * You can do a dry run with the -n flag: rename -n "s/ /_/g" * Use sh... for i in *' '*; do mv "$i" `echo $i | sed -e 's/ /_/g'`; done If you want to try this out before pulling the trigger just change mv to echo mv . What if you want to apply the replace task recursively ? How would

How do I set up Vim autoindentation properly for editing Python files?

半世苍凉 提交于 2019-12-02 13:50:15
I've trouble setting up Vim (7.1.xxx) for editing Python files (*.py). Indenting seems to be broken (optimal 4 spaces). I've followed some tutorials I found via Google. Still no effect :/ Please help. I use this on my macbook: " configure expanding of tabs for various file types au BufRead,BufNewFile *.py set expandtab au BufRead,BufNewFile *.c set noexpandtab au BufRead,BufNewFile *.h set noexpandtab au BufRead,BufNewFile Makefile* set noexpandtab " -------------------------------------------------------------------------------- " configure editor with tabs and nice stuff... " ---------------

How to replace all occurrences of two substrings with str_replace()?

寵の児 提交于 2019-12-02 12:52:34
Currently I have this code which replaces any double space with a <br /> . It works as expected: <tr class="' . ($counter++ % 2 ? "odd" : "even") . '"> <td>Garments:</td> <td>' . str_replace(' ', '<br /><br />', trim($result['garment_type'] ) ) . '</td> </tr> However I want to do another str_replace() on the same line to replace any single spaces with a pipe character | . I tried duplicating the code but that just creates another TD for me. Any help would be appreciated. The order of the array does matter otherwise you will get <br|/> instead of <br /> so try: str_replace(array(' ','||'),

How do I use a variable containing a filename with spaces in a bash script?

≯℡__Kan透↙ 提交于 2019-12-02 04:43:06
问题 I have a simple bash script running on OS X that removes specific files and directories and copies new ones in their place. One Mac .app directory contains a space, and when I run the script there is a "No such file or directory" error. Here is the relevant code. A good amount has been cut out, so simply hard coding these differently isn't possible (the variables must be broken up as they are): CP="cp -Rf" INSTALL_DIR="/Applications/" APP="The App.app" NEWAPP="$HOME/Downloads/The App.app" $CP

Regex - match a string without having spaces

早过忘川 提交于 2019-12-02 03:06:47
问题 Building an regular expression that will reject an input string which contain spaces. I have a following expression, but its not working as well; ^[a-zA-Z0-9!@#*()+{}[\\];:,|\/\\\\_\S-]+$ Valid case String123/test //string without space Invalid case String123/ test // contains space in between string String 123/test // contains space in between string String123/test // contains leading\trailing space i.e; I have to white list strings which does not contain any spaces. 回答1: You may use \S \S

What's wrong with putting spaces in $_GET variables

不问归期 提交于 2019-12-01 17:52:05
If I for example have my url looking like index.php?category=IT%20&%20Soft. Then i try to print "$_GET[category]" i only get "IT" and not "IT & Soft". What is wrong here? It's frustrating me. The problem is not the spaces, but the ampersand. Use %26 instead, like this: index.php?category=IT%20%26%20Soft The ampersand indicates that you are beginning another field (like category=IT&subcategory=somethingelse ). You can see a list of reserved characters on Wikipedia . Spaces and ampersands (&) aren't valid and need to be encoded for use in parameter values. Run your arguments through 'urlencode'