Questions tagged [whitespace]

combination of spaces, tabs, or newlines which create "empty" space in a line or column

Filter by
Sorted by
Tagged with
-1
votes
1answer
34 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
2answers
39 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 '...
0
votes
1answer
209 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
3answers
23 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
3answers
164 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 ...
1
vote
1answer
315 views

exporting variables from environment file with spaces in values

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): ++...
0
votes
2answers
53 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
1answer
62 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
0answers
31 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
1answer
77 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
2answers
35 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 --...
1
vote
1answer
77 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
3answers
380 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 ...
0
votes
2answers
1k 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
2answers
228 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
1answer
174 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 ...
0
votes
2answers
435 views

Remove new line, space from file

I have many files in a directory each like so: AAA AA AAAAAA A AAAA I want to end up with this: AAAAAAAAAAAAAAAA So that when I run: find ./ -name '*' -exec wc -m {} + I get back 16, not 20+ ...
0
votes
1answer
89 views

Replacing tabs with spaces from nth column to last column

I have a tab-separated file which looks as follows: GCF_000014165.1_ASM1416v1.dist_nbr_anntn WP_011558474.1 1155234 1156286 44173 polyketide synthase [Mycobacterium] GCF_000014165....
12
votes
3answers
2k views

What difference does it make matching a word with/without a trailing whitespace?

I am learning shell-scripting and for that I am using HackerRank. There is a question related to sed on the same site: 'Sed' command #1: For each line in a given input file, transform the first ...
0
votes
4answers
351 views

Grep a file which has spaces on it by expanding a variable

I have a find result saved in a variable and I am protecting the spaces in filenames by adding a single quotes around the output. So the for loop works flawlessly. My problem is when I intend to ...
0
votes
1answer
43 views

output of watch several commands not clear

I am restoring a database backup on my server and i need to watch output of df -h and restore utility db2pd -utilities. I tried this: watch -n 2 "db2pd -utilities && df -h output(summarized): ...
1
vote
2answers
611 views

How to sort a file with multiple delimiters?

Listing the available patches in openSUSE results in the following output. The command that results int the details below is zypper patches. The same result is also displayed when running the ...
0
votes
1answer
68 views

automatically repair rsnapshot config: replace spaces with tabs

rsnapshot is quite picky in its config: the commands have to be separated by TABs and not spaces. if you use rsnapshot configtest you see the errors, but how can I automatically repair the errors ...
9
votes
3answers
5k 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 ...
0
votes
2answers
287 views

Gnu Sed: Space Character class not matching for end of line character

Pattern: abc followed by space or is the last character in a line. orig="abc[[:space:]]+"; new=Hello sed -i -r -e "s|${orig}|${new}|g" ./file ; File: abc abcd abc abc d After executing: abc abcd ...
0
votes
2answers
961 views

bash: convert array into string preserving white spaces

I am just trying to convert an array into string, while preserving the white spaces. This is what I have: INPUT=$1 readarray -t arr < <(grep -o . <<< "$INPUT") echo "${arr[*]}" I ...
-1
votes
2answers
455 views

How to trim the spaces from first and last of the variable string in Linux? [closed]

I am trying to remove white spaces from each variable string. I tried with below command but no use. a="HARISH , SAM" echo $a|sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
0
votes
1answer
333 views

sed alters windows line endings unintentionally. How can I avoid that?

I am developing in linux a portable application, in which I wanted to remove trailing spaces from some source files, which have windows style line endings. The line endings should not be changed to ...
0
votes
2answers
1k views

sed: remove extra whitespace to single whitespace between strings while leaving leading tabs intact

I have a code: 1 /** 2 a b c 3 **/ 4 int main() { 5 int x; 6 if ( condition) { 7 return x; 8 } 9 } I need to change multiple whitespaces between ...
0
votes
2answers
147 views

Unix command to remove space from a file name

I have a file whose file name has a space like First Name_20180810.csv. The date (20180810 in the above example) changes daily in the filename. How can I rename First Name_*.csv to be FirstName_*.csv?...
6
votes
1answer
661 views

How to compile Linux kernel modules within white-space-separated directories under the following makefile?

I was trying to compile a kernel module source code, until I noticed that some whitespaces where causing mismatched path names. The directory under which I found myself was: axor@vacuum:~/software/CS ...
1
vote
1answer
139 views

Bash script Issue parsing text in line with whitespace characters

I have a list of commands to parse through for an audit, similar to this: 1. -a *policy name=PolicyName -a *policy workflow name=PolicyWorkflow -a *policy action name=PolicyAction -s Server -b ...
1
vote
3answers
1k views

How to left pad a column in Bash

I have a bash script that prints the following results: 120,900 1160,001 80,730 600,165 6,310 1111,203 I would like to left pad that so the result will be: 120,900 1160,001 80,730 600,165 6,...
1
vote
1answer
274 views

Bash script read a string with whitespace [duplicate]

I am trying to write a quick bash script to automatically git push to multiple branches at once. My issue is, when I enter my commit message as a read variable, bash and git freak out at the use of ...
0
votes
1answer
4k views

Using string with whitespace in the subprocess.call function in python

I am trying to use ssh command in the subprocess.call function of Python 2.6.8 on Unix environment to call a remote script, and I need to provide a string parameter (with whitespaces) to the remote ...
2
votes
6answers
5k views

How can I trim the contents of a text file?

I want to remove all "blank" characters from the very beginning and the very end of a text file, including \n if exists. (basically mimicking the behaviour of trim() function of most programming ...
1
vote
2answers
783 views

Replace a specific line keeping identation

I have a file that has indentation. I want to replace a specific line but keep the indentation. The file has a line such as \t\t customerId = "123" // has indentation in the start of line I ...
0
votes
2answers
3k views

Correct way to match a leading space with sed (all of them)?

How to match a leading space with sed (all of them)? I'm not talking about leading tabs, but rather only on leading spaces. From a small test I did in Nano this seems to be correct: sed "s/^ //g" ...
2
votes
1answer
7k views

Binary operator expected - quoting question for shell script args

I have a question on how I'm adding arguments when executing a shell script. I have a simple script which helps me block ip ranges: ~/block_ip.sh: if [ ! $3 ] then echo "usage ~/block_ip.sh (DROP/...
2
votes
4answers
433 views

Ignore spacing between echo strings

I use echo to print two strings into a file in either of these two commands: echo -e "\n""x" >> ~/file echo -e "\n" "x" >> ~/file The first result is: x The second result is: x I ...
0
votes
1answer
119 views

script parameter containing spaces invoking mediainfo

I'd like to create a small shell script that will tell me the duration of a video whose file name is passed to it as a parameter. It'd be something like this: $ script_name "file name with spaces....
2
votes
1answer
83 views

Differences in whitespaces between bash script and interactive shell

Please advice why this happens. from a Linux bash shell: ps PID TTY TIME CMD 20406 pts/0 00:00:01 bash 26896 pts/0 00:00:00 ps I run the follwing str="a b c d" printf "%s\n" ` echo ...
2
votes
1answer
249 views

Remove whitespace only between two characters { and } in file [duplicate]

I have file with json values : abc={"adf": "def", "abc2":"def2", "abc3" : "def3" } abc4= 1 abc = {hello : world, hello:"a"} I want to remove whitespace from everywhere in between { and } and not ...
3
votes
1answer
2k views

how to get less to show tabs as tabs?

When I view data with tabs in less, tab characters are expanded to spaces. If I then copy them directly out of my terminal using ctrl-c, they copy as spaces. On the other hand, more preserves tab ...
2
votes
0answers
287 views

How to open a file in MonoDevelop with spaces in the path?

I have installed MonoDevelop using the instructions here on my PC running Arch Linux. I can successfully launch the MonoDevelop IDE using the command: flatpak run com.xamarin.MonoDevelop I can also ...
2
votes
1answer
2k views

How to display trailing whitespaces in the text file?

I'd like to be able to print and see the trailing whitespaces in the text file (just display, not remove). I've tried with cat -v which suppose to display non-printing characters, but it doesn't ...
2
votes
1answer
425 views

Cut delimited with unescaped space?

I have a file with text in the format of: User\ Name My\ Password Notice this is actually a 2 column file, where columns contain escaped spaces. cut -d' ' -f2 produces Name but I want to produce My ...
1
vote
3answers
731 views

Print only certain columns while maintaining white space

I have some code that prints select columns from the output of lsblk. However, the spacing in the result makes it hard to read. Is there anyway to do this while maintaining the white space? echo "`...
6
votes
5answers
5k views

Replace any number of tabs and spaces with single new line in Linux? [closed]

I have a very large word list that has been damaged, maybe by improper vim exit or memory exhaustion? Everything in my word list should be left-justified. But now it is like this: Cat ...
0
votes
1answer
458 views

Any way to change the tab size of the diff command's output?

I'm on OSX and running a diff command like this, to create side-by-side output: $] diff -Bbwy --width=200 --suppress-common-lines file1.txt file2.txt > diff-output.txt It outputs my diffs just ...