Questions tagged [whitespace]

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

Filter by
Sorted by
Tagged with
0
votes
2answers
16 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 >...
0
votes
0answers
28 views

How to set spacing[tab] in bash correctly automatically? [duplicate]

I have a loop that checks if rpm is installed or not and displays output in tabular format, but for the rpm package with long names, the tabular format will not show as expected. Code: for package in ...
-1
votes
2answers
44 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
2answers
33 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
1answer
77 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 ...
4
votes
4answers
1k 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
1answer
39 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
3answers
48 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
3answers
87 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
6answers
2k 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
1answer
409 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
3answers
1k 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
1answer
126 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
1answer
965 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
1answer
35 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
2answers
138 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
1answer
65 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
1answer
102 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
209 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 '...
1
vote
1answer
2k 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
28 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
2answers
218 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 ...
3
votes
2answers
2k 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
2answers
412 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
350 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
36 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 ...
2
votes
1answer
435 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
133 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 --...
2
votes
1answer
582 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
1k 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
2answers
4k 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
2k 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
232 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
1k 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+ ...
1
vote
1answer
396 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
730 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
65 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
2k 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
155 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
19k 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
465 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
3k 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
1k 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
752 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
2k 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
504 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
1k 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
212 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
4k 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,...