Home » Infrastructure » Unix » Creating a file from few lines of another file
Creating a file from few lines of another file [message #146077] Tue, 08 November 2005 08:42 Go to next message
alka205
Messages: 18
Registered: August 2005
Junior Member
All
I have a file test.txt, it is a very large file, want to create another file test1.txt, which has only first 10 lines of test.txt

How can I do that from unix command?

Thanks
Re: Creating a file from few lines of another file [message #146083 is a reply to message #146077] Tue, 08 November 2005 09:16 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
oracle@mutation#cat dept.dat
10,ACCOUNTING,NEW YORK
20,>RESEARCH,DALLAS
30,SALES,CHICAGO
40,>OPERATIONS,BOSTON
oracle@mutation#head -2 dept.dat > top2lines
oracle@mutation#cat top2lines
10,ACCOUNTING,NEW YORK
20,>RESEARCH,DALLAS
oracle@mutation#
Re: Creating a file from few lines of another file [message #146175 is a reply to message #146083] Wed, 09 November 2005 00:51 Go to previous messageGo to next message
wofler
Messages: 4
Registered: February 2005
Location: Germany
Junior Member
Hi,

just do as follows:
cat text|head > text1

If you want more than 10 lines use
cat text|head -20 > text2


Regrads,
Wofler
Re: Creating a file from few lines of another file [message #146176 is a reply to message #146083] Wed, 09 November 2005 00:53 Go to previous message
wofler
Messages: 4
Registered: February 2005
Location: Germany
Junior Member
Hi,

just type the following:

cat dept.dat | head > dept1.dat

or if you want more than 10 lines:
cat dept.dat | head -20 > dept2.dat

or see man head, man tail

Reagrds,
wofler
Previous Topic: help needed: comparing two directory tree structures
Next Topic: Cannot open a file through vi
Goto Forum:
  


Current Time: Mon Nov 25 19:58:17 CST 2024