Unix Shell - Awk command to remove from a word to the end of file

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > September 2007 > Awk command to remove from a word to the end of file





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Awk command to remove from a word to the end of file
apogeusistemas@gmail.com

2007-09-17, 7:22 pm

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 !

Ed Morton

2007-09-17, 7:22 pm

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.
loki harfagr

2007-09-18, 1:27 pm

On Mon, 17 Sep 2007 16:32:43 -0500, Ed Morton wrote:

> apogeusistemas@gmail.com wrote:
> /^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=""
William James

2007-09-18, 7:19 pm

On Sep 18, 12:10 pm, loki harfagr <l...@DarkDesign.free.fr> wrote:
> On Mon, 17 Sep 2007 16:32:43 -0500, Ed Morton wrote:
>
>
>
>
>
>
> 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 ?-+)
>
>
>
> In this case, for golfers and elves here's a "twonky":
> $ awk '1;{exit}' RS="Sanford"



Good one.

awk '1==NR' RS="Sanford" file

romy

2007-09-19, 1:26 pm

try this :

cat file|sed '/Sanford/,$d'

William James

2007-09-19, 1:26 pm

On Sep 19, 12:30 pm, romy <rav...@gmail.com> wrote:
> try this :
>
> cat file|sed '/Sanford/,$d'


1. sed doesn't need cat.
2. sed isn't awk.

romy

2007-09-19, 1:26 pm



> 2. sed isn't awk. - my bad...


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com