Unix questions - Printing lines in UNIX

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > November 2006 > Printing lines in UNIX





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 Printing lines in UNIX
chaitu

2006-11-29, 7:22 pm

Hi ,

I have a doubt. I have a file and i want to print some 10
lines starting from a particular line. And i want to search this
particular line as grep SQL3109N and then start to print 10 lines after

that. How do i do that?


Thanks in advance.

Stephane CHAZELAS

2006-11-29, 7:22 pm

2006-11-29, 14:31(-08), chaitu:
> Hi ,
>
> I have a doubt. I have a file and i want to print some 10
> lines starting from a particular line. And i want to search this
> particular line as grep SQL3109N and then start to print 10 lines after

[...]


< file sed '/SQL3109N/,$!d' | head

--
Stéphane
Todd H.

2006-11-29, 7:22 pm

"chaitu" <chaituonweb@gmail.com> writes:

> Hi ,
>
> I have a doubt. I have a file and i want to print some 10
> lines starting from a particular line. And i want to search this
> particular line as grep SQL3109N and then start to print 10 lines after
>
> that. How do i do that?


I'd bang together a 3 line PERL script that'd do the search, then
print the next ten lines after that.

--
Todd H.
http://www.toddh.net/
chaitu

2006-11-29, 7:22 pm

Hi Steve,

It worked fine but does this command limit to only particular no of
lines? what if i have to print more? As i can see it prints only 10
lines. I have just taken 10 as an example. What if i have to print
more?

Thanks in advance


Stephane CHAZELAS wrote:
> 2006-11-29, 14:31(-08), chaitu:
> [...]
>=20
>=20
> < file sed '/SQL3109N/,$!d' | head
>=20
> --=20
> St=E9phane


boyd

2006-11-29, 7:22 pm

In article <1164841997.433380.124650@h54g2000cwb.googlegroups.com>,
"chaitu" <chaituonweb@gmail.com> wrote:
[vbcol=seagreen]
> Hi Steve,
>
> It worked fine but does this command limit to only particular no of
> lines? what if i have to print more? As i can see it prints only 10
> lines. I have just taken 10 as an example. What if i have to print
> more?
>
> Thanks in advance
>
>
> Stephane CHAZELAS wrote:

Read the man page, man head, and you will see that the number of lines
is selectable with -l

Boyd
Ed Morton

2006-11-29, 7:22 pm

chaitu wrote:

[please don't top-post, fixed below]

> Stephane CHAZELAS wrote:
>
>
>
> Hi Steve,
>
> It worked fine but does this command limit to only particular no of
> lines? what if i have to print more? As i can see it prints only 10
> lines. I have just taken 10 as an example. What if i have to print
> more?
>
> Thanks in advance


Since it's not clear what you really need, here's something I just
happened to post in comp.lang.awk earlier:

a) Print all records from some pattern:

awk '/pattern/{f=1}f' file

b) Print all records after some pattern:

awk 'f;/pattern/{f=1}' file

c) Print the Nth record after some pattern:

awk 'c&&!--c;/pattern/{c=N}' file

d) Print every record except the Nth record after some pattern:

awk 'c&&!--c{next}/pattern/{c=N}' file

e) Print the N records after some pattern:

awk 'c&&c--;/pattern/{c=N}' file

f) Print every record except the N records after some pattern:

awk 'c&&c--{next}/pattern/{c=N}' file

There are other approaches...

Regards,

Ed.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com