Questions tagged [whitespace]

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

Filter by
Sorted by
Tagged with
3
votes
2answers
29 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
36 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 ...
0
votes
3answers
52 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
56 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
55 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
2answers
65 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
23 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
106 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
33 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
160 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
40 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 ...
8
votes
3answers
2k 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
151 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
304 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
193 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
69 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
528 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
82 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
501 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
108 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
384 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
191 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
2k 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
2k 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
296 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
2k 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
4k 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
145 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
59 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
77 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
177 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
1k 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
230 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
1k 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
278 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
502 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
3k 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
265 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
380 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
102 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: ...
12
votes
4answers
1k 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
312 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 ...
4
votes
1answer
3k 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
77 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
879 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
30 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
469 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,...
2
votes
1answer
135 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: ...