Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File decimation

Status
Not open for further replies.

ooids

Technical User
May 2, 2001
21
US
Hi,

I need to write a script that decimates a file by a user specified amount.
e.g. Keep every 5th, 10th, 30th line etc.

Is there a standard unix command that i can use to do this or should i be looking at sed or awk?

Any ideas would be great.

Cheers!
 
Thanks feherke,

The sed command fails - "Unrecognized command: 3~3p" - any ideas why?

I can get the awk to work but only using "nawk" so thanks for that.

Cheers!
 
Update to my last post - the sed command runs on my Linux (Redhat) box - just not on my Sun (Solaris 2.8).

Thanks for the help!
 
Hi

Yes, there are incompatibilities between [tt]sed[/tt]s. I have GNU [tt]sed[/tt] 4.1.2 and GNU [tt]awk[/tt] 3.1.1. But the [tt]awk[/tt] code works with the [tt]gawk[/tt] --traditional option, so theoretically that is backward compatible. Seems to be exceptions too.

Feherke.
 
to print every 3-rd line:
Code:
sed -n 'n;n;p;' file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks,

Can you expain "n" and "p" - i have rarely used sed...
 
doing 'man sed' yields:
-n Suppress the default output.

n Copy the pattern space to the
standard output if default
output is not suppressed

Replace the pattern space with
the next line of input.

p Print. Copy the pattern space
to the standard output.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I was more after an example of decimation using your notation as it differs from the previous example that worked...

Cheers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top