All Questions

Tagged with
Filter by
Sorted by
Tagged with
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
53 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
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
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 ...
0
votes
2answers
153 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 ...
-1
votes
2answers
195 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
71 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
533 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 ...
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
304 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
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 ...
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 ...
3
votes
1answer
313 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 ...
5
votes
1answer
881 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 ...
1
vote
3answers
416 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'...
2
votes
2answers
6k views

How to add a string with spaces at the end of command output

I want to add a string with spaces at the end of each line of the output of ls command. #!/bin/sh STRING_WITH_SPACES="this should be at the end of output" ls -lh | sed 's|$| '$STRING_WITH_SPACES'|' ...
1
vote
1answer
1k views

Sed: search and replace a patten with special characters which has a arbitrary string in between

I have a load of nfo files which I want to make some global substitutions for some values within each file e.g. a.nfo has the value <set>Tonight&apos;s Menu ( June 2012 )</set> ...
24
votes
2answers
73k views

Removing all spaces, tabs, newlines, etc from a variable?

This is the error I am getting and it's failing because of a variable whose value is supposed to be 2 (I am getting this using a select * from tabel). I am getting spaces in that variable. + 0 != ...
7
votes
2answers
13k views

Strip trailing whitespace from files

The answer to removing trailing whitespace with sed has most of the answer, but I want sed -i 's/[ \t]*$//' $1 to be able to take arbitrary number of file arguments as a shell script on the command ...