Awk command to remove from a word to the end of file
Awk command to remove from a word to the end of file
am 17.09.2007 23:29:41 von apogeusistemas
Hi:
I need an awk script to remove lines in a file from Sanford word until
the end
of the file. Like this;
soalris> cat file
Until a new attorney general is confirmed by the Senate, Bush said,
Assistant Attorney General Peter D. Keisler will serve as acting
attorney general. Keisler oversaw the Bush administration's lengthy
legal fight over the rights of terrorism war-era prisoners at
Guantanamo Bay.
Sanford had announced his resignation from the department in early
September. He had been nominated by Bush earlier in the year for a
seat on the U.S. Court of Appeals for the District of Columbia
Circuit. The Senate has not acted on Keisler's nomination.
solaris>
Maybe anything like this:
#!/usr/bin/awk -f
$0 ~ /^Sanford/ { delete to the end of the file }
thank You !
Re: Awk command to remove from a word to the end of file
am 17.09.2007 23:32:43 von Ed Morton
apogeusistemas@gmail.com wrote:
> Hi:
>
> I need an awk script to remove lines in a file from Sanford word until
> the end
> of the file. Like this;
>
> soalris> cat file
> Until a new attorney general is confirmed by the Senate, Bush said,
> Assistant Attorney General Peter D. Keisler will serve as acting
> attorney general. Keisler oversaw the Bush administration's lengthy
> legal fight over the rights of terrorism war-era prisoners at
> Guantanamo Bay.
> Sanford had announced his resignation from the department in early
> September. He had been nominated by Bush earlier in the year for a
> seat on the U.S. Court of Appeals for the District of Columbia
> Circuit. The Senate has not acted on Keisler's nomination.
> solaris>
>
> Maybe anything like this:
> #!/usr/bin/awk -f
> $0 ~ /^Sanford/ { delete to the end of the file }
>
> thank You !
>
/^Sanford/{ exit }1
If the word can be in mid-line then:
sub(/Sanford.*/,""){ print; exit }1
Regards,
Ed.
Re: Awk command to remove from a word to the end of file
am 18.09.2007 19:10:51 von Loki Harfagr
On Mon, 17 Sep 2007 16:32:43 -0500, Ed Morton wrote:
> apogeusistemas@gmail.com wrote:
>> Hi:
>>
>> I need an awk script to remove lines in a file from Sanford word until
>> the end
>> of the file. Like this;
>>
>> soalris> cat file
>> Until a new attorney general is confirmed by the Senate, Bush said,
>> Assistant Attorney General Peter D. Keisler will serve as acting
>> attorney general. Keisler oversaw the Bush administration's lengthy
>> legal fight over the rights of terrorism war-era prisoners at
>> Guantanamo Bay.
>> Sanford had announced his resignation from the department in early
>> September. He had been nominated by Bush earlier in the year for a seat
>> on the U.S. Court of Appeals for the District of Columbia Circuit. The
>> Senate has not acted on Keisler's nomination. solaris>
>>
>> Maybe anything like this:
>> #!/usr/bin/awk -f
>> $0 ~ /^Sanford/ { delete to the end of the file }
>>
>> thank You !
>>
>>
> /^Sanford/{ exit }1
Sharp and neat, still I'm curious about the needs
of the OP, is that for a school or a contest for
some stained blond hair secretary ?-+)
> If the word can be in mid-line then:
>
> sub(/Sanford.*/,""){ print; exit }1
In this case, for golfers and elves here's a "twonky":
$ awk '1;{exit}' RS="Sanford"
example (with a different trigger):
$ awk '1;{exit}' RS="as acting" MISCFILES/sanford
Until a new attorney general is confirmed by the Senate, Bush said,
Assistant Attorney General Peter D. Keisler will serve
or, if you miss the final newline:
$ awk '1;{exit}' RS="as acting" ORS=""
Re: Awk command to remove from a word to the end of file
am 19.09.2007 01:28:02 von William James
On Sep 18, 12:10 pm, loki harfagr wrote:
> On Mon, 17 Sep 2007 16:32:43 -0500, Ed Morton wrote:
> > apogeusiste...@gmail.com wrote:
> >> Hi:
>
> >> I need an awk script to remove lines in a file from Sanford word until
> >> the end
> >> of the file. Like this;
>
> >> soalris> cat file
> >> Until a new attorney general is confirmed by the Senate, Bush said,
> >> Assistant Attorney General Peter D. Keisler will serve as acting
> >> attorney general. Keisler oversaw the Bush administration's lengthy
> >> legal fight over the rights of terrorism war-era prisoners at
> >> Guantanamo Bay.
> >> Sanford had announced his resignation from the department in early
> >> September. He had been nominated by Bush earlier in the year for a seat
> >> on the U.S. Court of Appeals for the District of Columbia Circuit. The
> >> Senate has not acted on Keisler's nomination. solaris>
>
> >> Maybe anything like this:
> >> #!/usr/bin/awk -f
> >> $0 ~ /^Sanford/ { delete to the end of the file }
>
> >> thank You !
>
> > /^Sanford/{ exit }1
>
> Sharp and neat, still I'm curious about the needs
> of the OP, is that for a school or a contest for
> some stained blond hair secretary ?-+)
>
> > If the word can be in mid-line then:
>
> > sub(/Sanford.*/,""){ print; exit }1
>
> In this case, for golfers and elves here's a "twonky":
> $ awk '1;{exit}' RS="Sanford"
Good one.
awk '1==NR' RS="Sanford" file
Re: Awk command to remove from a word to the end of file
am 19.09.2007 19:30:26 von rave25
try this :
cat file|sed '/Sanford/,$d'
Re: Awk command to remove from a word to the end of file
am 19.09.2007 19:49:44 von William James
On Sep 19, 12:30 pm, romy wrote:
> try this :
>
> cat file|sed '/Sanford/,$d'
1. sed doesn't need cat.
2. sed isn't awk.
Re: Awk command to remove from a word to the end of file
am 19.09.2007 19:53:35 von rave25
> 2. sed isn't awk. - my bad...