LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Cat and Sed Command Help. (https://www.linuxquestions.org/questions/linux-general-1/cat-and-sed-command-help-457334/)

homey 06-23-2006 12:21 PM

Last gasp for me. :)
Code:

sed '/.* A/,/TER/{/HET/d}' file.txt

or

sed '/^HET*/d' file.txt


vidyashankara 06-23-2006 12:37 PM

Quote:

Originally Posted by homey
Last gasp for me. :)
Code:

sed '/.* A/,/TER/{/HET/d}' file.txt

or

sed '/^HET*/d' file.txt



I figured out what the problem is.

SED looks for the start string more then once. Is there a way to limit SED to start looking and stop look just once?

spirit receiver 06-23-2006 12:59 PM

How about beginning with the first line?
Code:

sed -n "0,/^TER/p" file.txt

vidyashankara 06-23-2006 01:12 PM

Quote:

Originally Posted by spirit receiver
How about beginning with the first line?
Code:

sed -n "0,/^TER/p" file.txt

I have some text before " HETATM...............A " that i dont want to select.

The problem is after TER, there is another line with " HETATM...............A ", I dont want anything before " HETATM...............A " and after "TER". SED reads the lines after TER too. How do i avoid that?

This is my command right now

sed -n "/^ATOM\|HETA.................A/, /^TER/p"

It should read if the line starts with ATOM or HETA followed by 16 characters and then A.

The 16 characters can be anything...

XavierP 06-23-2006 01:13 PM

Threads merged because they are essentially the same.

vidyashankara 06-23-2006 01:16 PM

Quote:

Originally Posted by XavierP
Threads merged because they are essentially the same.


is there a way to read just the first thread?

spirit receiver 06-23-2006 01:22 PM

Code:

sed -ne '0,/^TER/ !d' -e '/^.\{14\}A/,$ p' file.txt

vidyashankara 06-23-2006 01:32 PM

Quote:

Originally Posted by spirit receiver
Code:

sed -ne '0,/^TER/ !d' -e '/^.\{14\}A/,$ p' file.txt

There is a complication to that. I am calling the command from PHP.

The file is in the following format

ATOM[or HETA] [14 random charaters] A
100 lines like this
TER

ATOM[or HETA] [14 random charaters] B
100 lines like this
TER

ATOM[or HETA] [14 random charaters] C
100 lines like this
TER

HETA [14 random charaters] A
100 lines like this
TER
HETA [14 random charaters] B
100 lines like this
TER

So i need to get A, B and C[Starting with ATOM or HETA] into seperate files. but i dont want the lines if the whole string starts only with HETA.

So i want
ATOM[or HETA] [14 random charaters] A
100 lines like this
TER

into A.txt

and
ATOM[or HETA] [14 random charaters] B
100 lines like this
TER

into B.txt

so the command should not have '0,/^TER/ !d' as it will count only A and not B or C.


All times are GMT -5. The time now is 06:01 PM.