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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting specific lines from a file

Status
Not open for further replies.

Ambatim

Programmer
Feb 28, 2002
110
IN
I am using the follwing command to extract lines from 10 to 20 from a

Hello Gurus,

I want to extract lines from 10 to 20 from a file and write them to another file. Line length in the file is 1187 characters. I am using the follwing command for this. After I execute this command I am not getting the command prompt back. It hangs ...

sed -n 10,20p file > file1

What is wrong in this command? Is the line length giving the problem ???

Any solution ??

Thanks in advance
Mallik
Thanks in advance
Mallik
 
Hi,
I don't know which unix you are using while extracting lines from a file and the problem may be platform demepndent. I've checked your sed command on hp-ux and it works fine with lines lenghts even longer then 1187 characters.
You can also try: head -n 20 file | tail -n 10 > file2.
If it hangs check if other commands (vi, cat) work fine with your file (maybe the file is corrupted?).

Cheers,
mewa
 
Hi Mewa,

I am using HP-UX.

It is working fine but it takes some time to get the prompt as the file size id 120MB.

Any how thank you very much.

Regards
Mallik Thanks in advance
Mallik
 
Why not have sed quit after the 20th line like this:

sed -n '10,20p; 20q' file > file1
 
You never stated what Platform you were using so the tool that you need is one of the following, truss, par, tusc, kdump or strace. Run the command in front of your sed command, you will get a list of system calls as they happen. Wait to see which one of these system call just says waiting or sleeping that is probally where the problem is. I would also try that same sed command on a different file but on the same Filesystem to see if that may be the problem.




B.T.W truss: is for Solaris and FreeBSD, par: is for SGI, tusc: is for HPUX, kdump: is for OpenBSD and finally strace is for Linux.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top