LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed/grep new lines in text (https://www.linuxquestions.org/questions/linux-newbie-8/sed-grep-new-lines-in-text-669764/)

hk20 09-13-2008 06:27 PM

sed/grep new lines in text
 
Hello,

How do you stop sed or grep from putting a string on a new line?
I am working with a text file, and it is treating my spaces as newlines.

ex:
cat blah.txt | sed /\"/s/\"//g

INPUT:

"This is a test"
"Test1"
"Test2"


output:

This
is
a
test
Test1
Test2


Thanks

Mr. C. 09-13-2008 06:34 PM

I'm not seeing results you see:

Code:

$ cat in
"This is a test"
"Test1"
"Test2"
$  sed /\"/s/\"//g in
This is a test
Test1
Test2

Note that I replaced your useless use of cat; nearly all utilities can read files specified as command line arguments.

Code:

$  sed 's/"//g' in
This is a test
Test1
Test2

Note that I removed the addressing portion (/\"/) as it is unnecessary in your case. No substitution could occur unless the line contains a double quote anyway, right? Also, it is more common to use single quotes to quote the entire sed expression, as it makes reading the expression clearer.

hk20 09-13-2008 06:47 PM

Thank You for the pointer, I will do some reading up on sed.


All times are GMT -5. The time now is 08:34 PM.