whitespace

How to use unix `mv` to rename files with unicode spaces(not U+20)?

How to use unix `mv` to rename files with unicode spaces(not U+20)? $ ls cn* cn blah blah.txt $ ls cn * ls: cannot access ‘cn *’: No such file or directory $ ls cn*|hexdump -C 00000000 63 6e e2 80 85 62 6c 61 68 c2 a0 62 6c 61 68 2e |cn…blah..blah.| 00000010 74 78 …

Total answers: 1

Why does a backslash at the end of the line place undue whitespace?

Why does a backslash at the end of the line place undue whitespace? I wanted: #!/bin/bash cmd –options option=value, option=value, option=value, option=value But running with bash -x I got: cmd –options option=value, option=value, option=value, option=value That causes an error. How can I do this so bash doesn’t automatically place this blank space? Asked By: rhuanpk …

Total answers: 4

Expand tabs in file with utf8 characters

Expand tabs in file with utf8 characters I use expand to expand tabs to spaces. For utf8 files expand doesn’t work correctly. E.g. in ćta tab is expanded to 6 spaces while in ata to 7 spaces. How do I make it work for utf8 files? Asked By: Marcin Król || Source You could use …

Total answers: 1

Adding 10 whitespace characters using sed

Adding 10 whitespace characters using sed I have written a script that replaces a string, but I need to add the 10 whitespace characters back. I can add it back by pressing space 10 times, and that works, but this looks hideous in my script. My script: sed -i ‘s/server.os[ t]*$freebsd/server.os $linux/g’ ~/var/log.txt I would …

Total answers: 3

How can I test if a string has any ASCII white space characters in it?

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 stored in …

Total answers: 3

Shell function to center its first argument

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 whitespace from the string str=$(echo "$str" | sed -e ‘s/^[[:space:]]*//’ -e …

Total answers: 2

Whitespaces in alias bashrc

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 ""}’ Works well, so I decided to make it an alias. First, it seems that the whitespace here …

Total answers: 5

Replacing command line arguments while preserving spaces

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 point of contention. I’m presently doing this: set — $(echo $* | sed -e "s/$_ARG/–description="$_ID – …

Total answers: 3

detailed bash script with cp and grep will not work with spaces in filenames

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. Have tried everything, single quotes, double quotes, ticks, …

Total answers: 2

Strip leading and trailing whitespace when piping to GNU parallel

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 attempting to run git pull ‘ foo’ which is …

Total answers: 1

Bash for loop with string var containing spaces

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 "$f"; done This script also works: for f in ‘foo …

Total answers: 4

need script to rename files replacing double space with single space

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 names contain double spaces, and some of my home grown scripts …

Total answers: 2

How to find more than one space and replace it with one space?

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 goal? Asked By: user9371654 || …

Total answers: 2

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

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 occurrence of the word ‘the’ with ‘this’. …

Total answers: 3

How to print strings separated by TAB in bash?

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 ‘footbar’ printf ‘%st%sn’ foo bar Both of them print: foo bar Where the whitespace between the two is actually 5 spaces (as per selecting the output with mouse in Putty). …

Total answers: 3

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

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 8803/Operating System Concepts/Chapter 2/ch2$ ls Makefile simple.c The error into which I …

Total answers: 1

how to get less to show tabs as tabs?

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 characters, as do many other commands like tail and …

Total answers: 1

bash: whitespace-safe procedural use of find into select

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 *; do echo “$file”; done 1) file 2) file name 3) …

Total answers: 4

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

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 …

Total answers: 1