Linked Questions

5 votes
4 answers
4k views

How can I replace a newline with sed? [duplicate]

I've got text with whitespace (including a newline) that I need to replace. I'd like to use sed, but AIX doesn't seem to support the answers to sed newline questions I found. The version of bash I'm ...
user avatar
  • 153
5 votes
1 answer
32k views

Remove all the new lines in a text file using sed [duplicate]

I would like to remove all the new lines in my text file with sed, I use this code: sed -i-o 's/\n//g' mytext.txt but nothing changes. I must be missing something... That is the content of my mytext....
user avatar
  • 111
1 vote
2 answers
1k views

Replace newlines with sed (a la tr) [duplicate]

echo "hi,my,name,is" | sed 's/,/\n/g' >out.txt yields: hi my name is But in reverse: sed 's/\n/,/g' out.txt yields: hi my name is Why doesn't sed revert the operation with an inversion of ...
user avatar
0 votes
1 answer
30 views

sed does not replace #DRECONTENT [duplicate]

Hi Here is a snippet of what I am trying to replace in file. #DRECONTENT 1gjHRjT9VYIBd8NdLeKOYq1wvJjdsGtf36OmiB9CfreBQRQSz3aPqDZdZZaB92m8YTNVqCRL2d45/GLcrwCyQ93RkpJiQCMe6SfVmHEAcOoUU/...
user avatar
662 votes
4 answers
291k views

Why is printf better than echo?

I have heard that printf is better than echo. I can recall only one instance from my experience where I had to use printf because echo didn't work for feeding some text into some program on RHEL 5.8 ...
user avatar
  • 11.8k
256 votes
5 answers
61k views

Why is using a shell loop to process text considered bad practice?

Is using a while loop to process text generally considered bad practice in POSIX shells? As Stéphane Chazelas pointed out, some of the reasons for not using shell loop are conceptual, reliability, ...
user avatar
  • 144k
258 votes
4 answers
42k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
user avatar
21 votes
8 answers
38k views

Turning separate lines into a comma separated list with quoted entries

I have the following data (a list of R packages parsed from a Rmarkdown file), that I want to turn into a list I can pass to R to install: d3heatmap data.table ggplot2 htmltools htmlwidgets ...
user avatar
  • 333
1 vote
3 answers
5k views

How to read input lines with newline characters from command line?

I found this to get user input from the command line. But it is failing into recognizing the new line characters I put into the input. Doing: #!/bin/bash read -e -p "Multiline input=" variable; ...
user avatar
  • 619
2 votes
1 answer
743 views

AWK don't match line feed \n on gsub

AWK don't match line feed \n on gsub(). Want change only the 'strawberry' fruit entry below. Would be great with sed too. It ignores \n as you can see on this script: cat << 'EOF' > ~/src ...
user avatar
  • 23
2 votes
2 answers
822 views

How to remove ^M and proceeding lines from a text file?

I have following lines with ^M (return carriage). I want to remove ^M+proceeding line. You can notice there is a new line after each ^M, which is not desired. I purpose is to remove control character ...
user avatar
  • 121