Questions tagged [whitespace]
combination of spaces, tabs, or newlines which create "empty" space in a line or column
159
questions
0
votes
3
answers
140
views
How can I test if a string has any ASCII white space characters in it?
How can I check if a string has any whitespace characters in it? I do not have to worry about things outside of ASCII for example unicode zero width characters etc. You can assume that the string is ...
0
votes
2
answers
44
views
Shell function to center its first argument
In the nano text editor, I can pipe the selection into a command, and I quite often need to center text, so I came up with the following code
center() {
str=$1
# Strip leading and trailing ...
-1
votes
2
answers
42
views
Unable to remove space for filenames [closed]
I'm unable to remove space from filenames as below, Please advise if any solution is there on this issue. thank you
/home/files:
Dec 14 22:10 testfiles
Dec 15 12:30 test file1
Dec 14 21:45 test ...
0
votes
5
answers
78
views
Whitespaces in alias bashrc
I use Bash
I wrote a command for printing only docker id separate with whitespaces on one line.
docker ps -a | grep -E '^[a-z0-9]{12}' -o | awk '{printf "%s ",$0} END {print ""}'
...
1
vote
1
answer
25
views
spaces in filenames -- general prevention strategies
Spaces in filenames are a problem which is as known as enervating. Nevertheless, there does not seem to be a big list how to prevent them, nor does prevention seem to be supported by the common static ...
0
votes
1
answer
145
views
Why does nano indent pasted text or code improperly?
When I copy and paste text from the clipboard, the code looks like
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
...
0
votes
0
answers
28
views
Nano: is there anyway to add space between marked lines?
It's easy to justify and indent lines, but is there a way to add spaces between them for clarity like in a double spaced word document?
0
votes
1
answer
52
views
GNU sed: append both BEFORE name start and AFTER name end (output is: "$ ls -xN")
Please could someone check if my GNU sed script is the nice way to do it or if it's some sort of bad / wrong hack :p
$ ls -xN
1
2
3
4
$ ls -xN | sed -E "s/(.{1})$/\1\.log/" | sed -E "s/...
3
votes
3
answers
879
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 ...
0
votes
0
answers
24
views
remove all files in one go with filenames having whitespaces [duplicate]
On my solaris, I have thousands of files and some of the files have leading, trailing and whitespaces in the middle of the filenames.
For example: ls -l '-CERT-UAB School of Dentistry - Ora_5551061....
0
votes
2
answers
99
views
detailed bash script with cp and grep will not work with spaces in filenames
I would never do it myself but people with Windows machines insist on putting spaces in filenames.
I've composed this detailed command which works perfectly except for the files with spaces in them. ...
1
vote
1
answer
47
views
Strip leading and trailing whitespace when piping to GNU parallel
When I try to write a pipeline like this:
git branch | rg '^\*' | parallel git pull {}
I run into a problem with whitespace. Because the branch names have leading whitespace, parallel ends up ...
0
votes
1
answer
388
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 '/^...
0
votes
2
answers
98
views
grep results with spaces and special chars
I am trying to grab results from lshw and add them to a a bash array so I can create a new string. I am using
lshw -class disk |egrep -A 7 .'-d' |grep 'product' |cut -b 17-
the output looks like this
...
0
votes
1
answer
146
views
tar invalid transform expression error due to whitespaces over ssh call
I am using tar --transform over SSH call to rename the documents during archiving based on array DOCUMENTNAMES.
tar -uvf /tmp/$TARGET''TVL_document.tgz'' --transform='s|'\${doc}'|'\$docname'|' -C /...
0
votes
0
answers
26
views
Execute command from string containing spaces [duplicate]
How to execute command from string containing spaces?
$ ls "xxx yyy"
a.exe
$ X="./xxx yyy/a.exe" ; $X
-bash: ./xxx: No such file or directory
$ X='./xxx yyy/a.exe' ; $X
-bash: ./...
1
vote
1
answer
34
views
How does unexpand command work with more than one tablist?
I tried reading the manual for unexpand as well as read the answer here but I do not understand how unexpand works with a tablist as an argument.
When I try the following (2 spaces and 3 spaces ...
3
votes
0
answers
522
views
zsh/oh-my-zsh: how to make tab completion add no trailing space for non-folder files?
I installed zsh and oh-my-zsh.
By default, when using tab completion zsh adds a trailing space for non-folder files.
For demonstration I created the following folders/files in a folder named ...
0
votes
2
answers
161
views
Grep is not retrieving string with space
I have a series of headings in a file that have names like this:
grep ">scaffold_3" DM_v6.1_unanchoredScaffolds.fasta
>scaffold_3
>scaffold_303
>scaffold_31
>scaffold_34
>...
1
vote
2
answers
1k
views
sed possible white space match
I have to modify some paramteres in a param file that may look like:
MY_VAR=YES
I want to use `sed and came up with this:
sed -i 's/MY_VAR=[A-Z]*/MY_VAR=NO/' sed.txt whih seems to work, now I also ...
0
votes
2
answers
49
views
Pass qouted filename with spaces in a bash variable [duplicate]
In a bash shell, consider this:
$ x="-name 'foo bar'"
$ find $x
find: paths must precede expression: `bar''
$ find -name 'foo bar'
./foo bar
What can I put in $x to make find $x behave like ...
3
votes
1
answer
96
views
Is there a trick to re-align tabular data in the terminal after filtering with grep?
Good example of what I'm getting at:
try doing ss -axl to show listening UNIX domain sockets. For example, this might give:
Netid State Recv-Q Send-Q ...
5
votes
4
answers
5k
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 "$...
0
votes
1
answer
42
views
How to differ strings with and without ending/starting spaces? [duplicate]
I need to format a text file (a Fortran source code) and change some keywords from small letters to capitals or vice versa.
I've made an array of possible keywords and have the following piece of the ...
1
vote
3
answers
111
views
avoid spaces and apostrophes problems with ls in a awk script [duplicate]
I have many identical files in two (local) devices, and it happens that I have renamed some, only in one device (A). I found the following way to rename the identical files in the other device (B), ...
0
votes
3
answers
224
views
find results containing space to be printed with enclosing quotes
How can find search results containing spaces to be printed with enclosing '' (a quote pair). Only if this result contains spaces, if there are not spaces in the path string, to remain as is.
2
votes
6
answers
4k
views
How to count spaces in text?
In the following example, there are 4 spaces before inet.
wolf@linux:~$ ip address show eth0 | grep 'inet '
inet 10.10.10.10/24 brd 10.10.10.255 scope global dynamic eth0
wolf@linux:~$
How do I ...
3
votes
1
answer
738
views
Can I make shell consider NBSP a whitespace character?
This seems like a common issue: you paste a simple command from somewhere into the terminal and it's not being understood by a shell:
$ echo test
$ zsh: command not found: echo test
The reason is ...
2
votes
3
answers
3k
views
Grep Lines from File with spaces
I have File which contains Records
qwe.google.com IN A 1.1.1.1
qwe.google.com IN {uneven-space} A{space}1.1.1.1
qwe.google.com IN CNAME asd.google.com
I need to grep all the lines which ...
0
votes
1
answer
263
views
need script to rename files replacing double space with single space
Can someone help me figure out how to remove double spaces from directory names?
I'm using a service which gives me a directory structure of files whose names contain spaces.
Sometimes the directory ...
11
votes
1
answer
1k
views
Why does this grep statement do the opposite of what I expect?
I have a file with some HTML and some text mixed in, I just wanted to use the text lines.
I was fooling around with grep, trying to get a way to exclude the lines that began with an HTML tag, even ...
1
vote
1
answer
59
views
How may I loop through a list that contain whitespaces?
I need to iterate through my list that sometimes contains whitespaces.
That is the script that I use right now
locate .txt > list
for book in $(cat list)
do
cp "${book}" /mnt/e/BOOK
done
I, ...
2
votes
2
answers
450
views
How to replace the leading tab (including tabs after some space characters) only?
I have some files that are indented by tabs or spaces or both. I want to convert leading tabs to spaces (one tab to 4 spaces). This includes tabs after some leading spaces. Below are some examples of ...
1
vote
1
answer
232
views
sed bash script is unexpectedly replacing character with space instead of newline [duplicate]
Using bash command syntax:
echo "The*quick*brown*fox"|sed s/*/\\n/g
I get the desired output:
The
quick
brown
fox
However in script:
IN_TXT="The*quick*brown*fox"
OUT_TXT=$(echo $IN_TXT|sed s/*/\\...
-1
votes
1
answer
216
views
bash function to handle space(s) from command line argument
Always typing c d.. or c d .. to move up one dir.
Placed function below in my .bash_profile, but only the first character before the white space -"c" is being interpreted instead of the entire set ...
0
votes
2
answers
375
views
For loop with grep and spaces
I seem to have a little bit of an issue with spaces when trying to use for loops and grep together. The whitespace is important because, for example, I'd like to match 'k117_19650 ', but not '...
4
votes
1
answer
3k
views
Nano - highlight trailing whitespaces
I use nano as my standard editor for a file type it has no build in syntax-highlighting for LilyPond. It is nothing I really need, though I'm missing out quite a lot of white-space characters at the ...
0
votes
3
answers
73
views
Not able to access files copied using double quote
By mistake, I have copied 100 files using the cp command as
$ cp file1 "/data/ file1"
$ cp file2 "/data/ file2"
note:- there is a space between /data and file2, file1
Within the /data directory, I ...
2
votes
2
answers
600
views
bash scripts: using whitespace
I've tried web search and search on that site but found only problems with usage of whitespace for strings in bash. However I'd like to understand general logic behind usage of whitespace in bash ...
4
votes
2
answers
3k
views
exporting variables from environment file with spaces in values [duplicate]
Say I have this .env file:
A=1
B=2
C="3 4 5"
If I run set -x; echo $(cat .env | xargs):
++ cat .env
++ xargs
+ echo A=1 B=2 C=3 4 5
A=1 B=2 C=3 4 5
If I run set -x; export $(cat .env | xargs):
++...
1
vote
2
answers
962
views
Replace characters after match with sed
I have a string:
172.16.1.5] "80 EE 73 2F 0B 40
I need to replace all the spaces after the ] " with a colon. Currently using sed -r 's/[ ]+/:/g' I get an output of 172.16.1.5]:"80:EE:73:2F:0B:40:, ...
0
votes
1
answer
722
views
Dealing with spaces in bash when piping the results from one command to another
I need to go recursively through several directories/files, in bash, replacing a certain string with another if it exists in a file. I had this solved in my script with the line:
grep -rl "...
2
votes
1
answer
77
views
SH/BASH: Store Command Parameter with Whitespace in Variable [duplicate]
I'm trying to store a command string in a variable for later execution. The problem is that the command includes a parameter argument with whitespace. When the command is executed, instead of seeing ...
1
vote
2
answers
938
views
Unwanted trailing white-spaces comes along on copy-paste
I'm using Tmux & Zsh (WSL) and am very frustrated with all the white-spaces that comes with when copy content from a file while using nano.
nano .zshrc
.
When using Shift+Right Mouse Button or ...
3
votes
2
answers
276
views
Remove trailing whitespace in df command
I have the following df command:
> df -h --output=used,avail,pcent /
Used Avail Use%
5.9G 12G 34%
Notice how there is a space before Used and 5.9GB
So I did the following:
> df -h --...
4
votes
1
answer
927
views
Using sed to replace a string where the replacement contains whitespace
I have the need to replace a single line in multiple files and have been playing around with sed for a solution. I am encountering this error:
sed: -e expression #1, char 31: unterminated `s' command
...
1
vote
3
answers
2k
views
How to find and replace seemingly a tab char using sed?
I have a line looks like this:
some.com *.some.com
The space is seemingly a tab space because when I move the keyboard arrow, one move will move me to the end of it (it does not seem multiple ...
1
vote
2
answers
5k
views
How to find more than one space and replace it with one space?
I want to find repeated spaces (more than one) and replace them with one space.
I tried:
sed -e 's/ []+/ /g' myfile.txt > myfile2.txt
This resulted in an empty file. Why? and how to achieve my ...
0
votes
2
answers
3k
views
Remove Multiple TABS in between data
I have a tab delimited file, but in a few records, I see multiple TABS in between data
Sample Data: M^I^I^I^IJaghoub (^I is tab delimiter in cat -vet output)
Required Output: MJaghoub
I have used ...
0
votes
1
answer
287
views
sed/awk/python replace all spaces between characters after string match
I want to delete all spaces between characters after an initial match. An example is
exmpl 0 t h i s a r e t he spaces to d e l e t e
exmpl 1 m o r e spaces to d e l
exmpl 2 o r s m t h completely d ...