Questions tagged [whitespace]
combination of spaces, tabs, or newlines which create "empty" space in a line or column
167 questions
423
votes
22
answers
859k
views
How do I trim leading and trailing whitespace from each line of some output?
I would like to remove all leading and trailing spaces and tabs from each line in an output.
Is there a simple tool like trim I could pipe my output into?
Example file:
test space at back
test ...
0
votes
2
answers
62
views
Is make's $(<D) affected by nearby spaces?
Is there any hope of using $(<D) here?
Any hope of avoiding the mystery dots?
$ cat Makefile
D=$(HOME)/Downloads
test: $D/DreamHost\ Web\ Panel\ _\ Mail\ _\ Message\ Filters.html
: mv "$&...
378
votes
6
answers
422k
views
Why does my shell script choke on whitespace or other special characters?
… or an introductory guide to robust filename handling and other string passing in shell scripts.
I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
2
votes
1
answer
588
views
How can I take a sub-array in bash of the first N elements of a string array with elements containing spaces?
This question is similar to this one but it differs from it:
Consider this array with string elements which may contain spaces:
a@W:$ arr=("eins" "zwei" "eins plus zwei" &...
7
votes
4
answers
3k
views
Why does a backslash at the end of the line place undue whitespace?
I wanted:
#!/bin/bash
cmd --options \
option=value,\
option=value,\
option=value,\
option=value
But running with bash -x I got:
cmd --options option=value, option=value, option=value, ...
0
votes
2
answers
118
views
One-liner piping from find/xargs with paths including spaces
The following question likely does not relate specifically to Vim. I use a Vim example, as this is where I encounter the issue.
Working on Ubuntu, I often open multiple files in Vim using tab pages:
$ ...
156
votes
6
answers
83k
views
Why does Vim indent pasted code incorrectly?
In Vim, if I paste this script:
#!/bin/sh
VAR=1
while ((VAR < 10))
do
echo "VAR1 is now $VAR"
((VAR = VAR +2))
done
echo "finish"
I get these strange results:
#!/bin/...
3
votes
1
answer
181
views
Showing whitespace in Ed
In Ed I can test for whitespace with this regex: g/ *$/p. I don't suppose there is a way of showing whitespace, perhaps by passing the contents of the buffer to another shell command?
1
vote
1
answer
120
views
How can I iterate over the white space separated words returned by a command substition?
I have the following simple shell command:
for x in $(echo one two three); do echo $x; done
When executed, it simply prints
one two three
on one line, i. e. the result of the command substitution is ...
1
vote
2
answers
2k
views
Include spaces and tabs in "awk" search and replace
Another user helped me earlier to fix something I'm doing with awk, where I search for a string at any point in all files and replace two numbers in the same line when I find it.
awk -i inplace '/^...
11
votes
4
answers
39k
views
How to print strings separated by TAB in bash?
I am trying to print two string separated by a TAB.
I have tried:
echo -e 'foo\tbar'
printf '%s\t%s\n' foo bar
Both of them print:
foo bar
Where the whitespace between the two is actually 5 ...
7
votes
4
answers
17k
views
Bash for loop with string var containing spaces
In my directory I have two files with space, foo bar and another file. I also have two files without space, file1 and file2.
The following script works:
for f in foo\ bar another\ file; do file "$...
85
votes
2
answers
28k
views
Why is bash not storing commands that start with spaces?
If I perform a sequence of commands like:
$ ls
$ grep abc file.txt
and then use the up arrow key to get the previous one, the terminal will show the last cmd (which is the grep here)
But if I do ...
55
votes
4
answers
146k
views
Removing all spaces, tabs, newlines, etc from a variable?
This is the error I am getting and it's failing because of a variable whose value is supposed to be 2 (I am getting this using a select * from tabel).
I am getting spaces in that variable.
+ 0 !=
...
3
votes
3
answers
2k
views
Replacing command line arguments while preserving spaces
I would like to selectively replace a command-line argument that is being passed to automatically format it for the downstream command being executed. The argument will have spaces and that is the ...