That should print anything between FOO and BAR, right?
Well, let's say I have file.txt that contains just one line "how are you today?".
Then I run something like the above and get:
It prints the line twice when I was expecting it to print just "are you".
I tried several text files with different content and also played around a little bit with quoting and regexps and in every case I got the line or the entire text duplicated.
I'm pretty sure the problem is mine and not sed's but I can't figure out what I'm doing wrong.
Any ideas?
- - - - - - - - -
Off Topic
Thanks to all of you out there. Reading this forum got me out of trouble many times
Because sed prints every line by default anyway, unless you use -n or unless you delete the line. The p command in that sed script also prints it. So, that script will print lines that match twice and lines that don't match once.
You can either use -n option or you can invert the logic:
Note the !. That deletes every line that does not match.
In a multiple line file, I get all the lines between the patterns, as expected, using the -n flag, without any extra output. .
When providing a one line file (or a line of text using | ), it prints out the whole line, which makes sense after reading what you explained in the other post.
I'm working on a file with several lines, so the -n does the trick. But I'm still curious on how to print a string between two patterns of a single line using sed.
Hi I'm having a problem with a sed command that I thought I was using correctly but apparently that's not the case.
I was hoping someone here could point out what it is I am doing wrong?
I am using the print, no print option for a matched pattern in sed. Everything seemed to be working fine... (2 Replies)
Hi I'm having a problem with a sed command that I thought I was using correctly but apparently that's not the case.
I was hoping someone here could point out what it is I am doing wrong?
I am using the print, no print option for a matched pattern in sed. Everything seemed to be working fine... (5 Replies)
I have 4000 files like
$cat clus_grp_seq10_g.phy
18 1002
anig_OJJ65951_1 ATGGTTTCGCAGCGTGATAGAGAATTGTTTAGGGATGATATTCGCTCGCGAGGAACGAAGCTCAATGCTGCCGAGCGCGAGAGTCTGCTAAGGCCATATCTGCCAGATCCGTCTGACCTTCCACGCAGGCCACTTCAGCGGCGCAAGAAGGTTCCTCG
aver_OOF92921_1 ... (1 Reply)
I accidentally saved a txt file in vi with the name ":q!".
no amount of regex tomfoolery I can think of will allow me to remove the file.
anyone got any ideas? (4 Replies)
Hi all,
I want to remove the remove bracket sign ( ) and put in the separate column I also want to remove the repeated entry like in first row in below input (PA156) is repeated
ESR1 (PA156) leflunomide (PA450192) (PA156) leflunomide (PA450192)
CHST3 (PA26503) docetaxel... (4 Replies)
if I wanted to know if the word DOG(followed by several random numbers) appears in col 1, how many times will that same word DOG* appeared in col 2? This is a very large file
Thanks! (7 Replies)
I have attached a file with few records. First 2 characters of each record are binary characters. I can remove it by
and it works fine. But
is behaving differently and removing more than expected characters. Can someone help me in accomplishing it through sed? Thanks in advance. (13 Replies)
I have a text file that I want to search for repeated lines and print those lines. These would be lines in the file that appear more than once. Is there a way to do this?
Thanks (4 Replies)