Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [whitespace]

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

0
votes
1answer
62 views

How to strip out white space of a filename

Opering System : RHEL 7 Bash Script: V_No=10.8.3 BUILD_VERSION=`echo ${V_No} | tr ' ' '_'` echo "File Name: Dev-${BUILD_VERSION}.jar" output: File Name: Dev-10.8.3 .jar expected output: File ...
0
votes
2answers
42 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
34 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
44 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
19 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
150 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
3answers
75 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
405 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
83 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
97 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
77 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
981 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
736 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
68 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
743 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" ...
1
vote
1answer
2k 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
98 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
37 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
72 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
107 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 ...
2
votes
1answer
624 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
173 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 ...
1
vote
1answer
620 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
86 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
182 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
2k 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
144 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 ...
2
votes
1answer
202 views

Quoting a path that contains spaces, in FreeBSD - why doesn't it always work?

I have a directory on my FreeBSD server whose contents are created by Windows users over Samba. The filenames and paths within it sometimes contain spaces, as is common in the Windows world. I just ...
2
votes
1answer
2k views

Passing arguments with spaces and quotes to a script (without quoting everything)

The following works great on the command-line: $ ffmpeg -i input.m4a -metadata 'title=Spaces and $pecial char'\''s' output.m4a How do I parameterize this command and use it in a script/function? I ...
1
vote
1answer
63 views

Passing paths and filenames to a program from bash script

I use a utility called mp3wrap which combines multiple mp3s into one. Say I have a directory "album 1" containing three files "track 1.mp3", "track 2.mp3" and "track 3.mp3". I will run the following: ...
11
votes
4answers
832 views

bash: whitespace-safe procedural use of find into select

Given these file names: $ ls -1 file file name otherfile bash itself does perfectly fine with embedded whitespace: $ for file in *; do echo "$file"; done file file name otherfile $ select file in *;...
3
votes
1answer
212 views

Zsh preexec - How to trim all leading indentations from a codeblock?

Say I copy the following codeblock from a .md handbook which incldes some information and a few codeblocks (hence it's not a script file): ⇨⇨⇨⇨( ⇨⇨⇨⇨Indented commands... ⇨⇨⇨⇨) The Zsh preexec ...
2
votes
1answer
2k views

Posix Character Sets difference between [[:blank:]] and [[:space:]]?

On this website it says: [[:blank:]] space and tab characters [[:space:]] whitespace characters What's the difference between space and tab characters and whitespace characters? To me, they ...
1
vote
1answer
71 views

Can I force column to emit whitespaces instead of tabs?

I'd like to tabularize a file with the column command: $ column -c 60 file.txt The output is nice on the screen, but unusable for my purposes because the items are seperated by tabs. for further ...
5
votes
1answer
598 views

Replace each tab ONLY at the beginning of each line with spaces

So replacing all tabs in a file with spaces is not hard. In vim for example, I can do %s/\t/ /gc And if I want to replace the ones at the beginning of each line, not the one in the middle I can ...
0
votes
0answers
29 views

Passing filenames with space between scripts [duplicate]

I've got a script that processes filenames given as parameters on the command line. This is a stripped down version to demonstrate the processing: #!/bin/bash # Just a test to see if parameter ...
1
vote
1answer
406 views

Git Server: ignore whitespace changes in new commits

I found a lot of ways to deal with the whitespace problem in Git, but all of them require some sort of action on the user side: configure Git to ignore ws changes, setup a pre-commit hook with warning,...
3
votes
1answer
104 views

Wordsplitting occurring in quoted variable

I'm trying to create a dialog menu based on the results of the lsblk command. My goal is to read the first word as the menu item and the remaining words as the menu item description. For example: ...
1
vote
2answers
201 views

Entering a folder with whitespaces and escape characters using bash

I have access to a list of folders that have a format like lastname, firstname(id) When I try to enter the folder from the terminal, it looks like cd test/lastname,\ firstname\(id\) I am not sure ...
4
votes
2answers
225 views

Maintain filenames as separate arguments in successive commands

First, if you have a better title suggestion, please comment, I'm happy to refine it. A disclaimer: This isn't related to one specific command like ls or grep, although I use them in the examples, ...
0
votes
3answers
1k views

Removing space at the beginning of the variable data

I would like to ask if how can I remove the space in the beginning of the stored data of the variable. I had an auto-generated script that will get MySQL COUNT from the DB. MYSQL COUNT SCRIPT-> .ini ...
-1
votes
1answer
111 views

Read file and write output in another file using shell script

My input file is: Employee e_id e_name 100 abc 101 xyz 102 pqr Salary e_id e_salary 100 12345 101 67890 Dependents e_id depp1 depp2 100 qwer tyui 102 asdf ghjkl I want the output line by line as ...
10
votes
4answers
2k views

Why does cut fail with bash and not zsh?

I create a file with tab-delimited fields. echo foo$'\t'bar$'\t'baz$'\n'foo$'\t'bar$'\t'baz > input I have the following script named zsh.sh #!/usr/bin/env zsh while read line; do <<&...
1
vote
3answers
288 views

How to delete whitespace surrounding equal signs in a string?

I'm trying to determine a way to delete leading and trailing whitespace surrounding the equal sign from a string. The whitespace may (or may not) be present. There may be 0, 1 or more equal signs. I'...
1
vote
1answer
108 views

How can I edit my bash script to account for whitespace entries? [duplicate]

I made a script to automate ffmpeg conversion from mkv > m4v > open the m4v in Subler.app to import the metadata manually, at which point I'll move the file into my iTunes library. I use iTunes ...
2
votes
1answer
272 views

Change to a directory containing a space

I'm using a MacBook with OS X installed. I'm on Terminal trying to go to a directory. So I'm in Home and I use the command ls and there is a VirtualBox VMs directory. But when I try to do cd ...
4
votes
1answer
4k views

Octals 302 240 together seem to correspond to non-breaking space

By looking at a particular line of a text file (say, the 1123th, see below), it seems that there is a non-breaking space, but I am not sure: $ cat myfile.csv | sed -n 1123p | cut -f2 Lisztes feher $ ...
1
vote
0answers
21 views

Creating command from some of the arguments to a bash script including whitespaces [duplicate]

I have a bash script that takes some arguments and uses some of them to loop over some action while some others (those of the form 'a=b') are passed to that action. Essentially, it looks like args= ...
1
vote
2answers
203 views

How to allow spaces in directories when using find -exec together with basename?

I'm trying to find all the directories in a given path, and create soft links inside those directories into directories with the same names at another location. Many of the directories have spaces in ...
5
votes
4answers
5k views

How to make xargs handle spaces and special chars from cat?

I have a file that contains a list of names. i.e.: Long Name One (001) Long Name Two (201) Long Name Three (123) ... with spaces and some special characters. I wanted to make directories out of ...