Visit Our UNIX and Linux User Community


How to remove first 100 line in a file?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to remove first 100 line in a file?
# 1  
Old 07-24-2009
How to remove first 100 line in a file?

Hello,

I want to find a way to remove first few line in a file in linux.
I know sed -e but the problem is that I cant redirect my output to some file and rename it because this file is created by java code and point to Inode rather than file name.

Please suggest me a single line command that will erase first 100 lines of file.

Thanks in advance,
Y
# 2  
Old 07-24-2009
You can use sed with in-place editing:
Code:
sed -i -e '1,100d' file

# 3  
Old 07-24-2009
Thanks a lot!!

---------- Post updated at 03:22 PM ---------- Previous update was at 01:47 PM ----------

One more question, it works well on Linux but doesnt work on SolarisSmilie

Any idea about solaris??

Appretiate your help
# 4  
Old 07-24-2009
In-place editing is a feature of GNU sed, and sadly not available on most other Unices. Either use the GNU version or give Perl a try:
Code:
perl -i -ne 'print if $.>100' file

# 5  
Old 07-24-2009
Thank you !!
It worked fine Smilie

Appretiate you quick responseSmilie
# 6  
Old 07-28-2009
A solution using awk, just to make the group complete Smilie
awk '{ if(NR > 4) print $0; }' input > output

---------- Post updated at 03:33 AM ---------- Previous update was at 03:31 AM ----------

Should be 100 instead of 4, of course. I just didn't find a file so large to give it a quick shot...
Btw, an edit function would be really nice.
# 7  
Old 07-28-2009
Let's not forget about:
Code:
d100d

in Vi. Smilie

Note: Yes, I do know the OP did not want to actually open the file. Just putting it out there for the archives.

Previous Thread | Next Thread
Test Your Knowledge in Computers #435
Difficulty: Medium
Angular and AngularJS are web application frameworks to use for developing multi-page web applications.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove first line of file

How can I use bash to remove the first line of a file? (3 Replies)
Discussion started by: locoroco
3 Replies

2. Shell Programming and Scripting

Remove line from file and read file line by line

I have a file output.txt. File looks like this name1 10 name2 2 name3 5 I get a number n and I need to remove all lines which has number (after name) smaller or equal to n number. After that I need to write lines from file and my output must be like this: Output: 'name1 10' Output: 'name2... (1 Reply)
Discussion started by: kubo12312
1 Replies

3. Shell Programming and Scripting

How to remove last line of the file

Hi, unix gurus, I need to remove last line of the file. anybody can help me thanks in advance (7 Replies)
Discussion started by: ken002
7 Replies

4. Shell Programming and Scripting

Remove first line of file

Is there an easy way to remove the first line of a file so that the file: aaron benjamin cecilia daniel elliot fernando would become benjamin cecilia daniel elliot fernando (4 Replies)
Discussion started by: locoroco
4 Replies

5. Shell Programming and Scripting

How to remove a line from a file

./xxibe ./xxibe/11.5.0 ./xxibe/11.5.0/admin ./xxcyb/11.5.0/reports/US ./xxkintana ./xxkintana/1016454 ./xxkintana/1016454/backup ./xxkintana/1016454/updates ./xxcpf/11.5.0/xml_gw ./xxcse ./xxcse/11.5.0 ./xxcse/11.5.0/admin I have a file (sample.txt) this file contains above text. I... (9 Replies)
Discussion started by: gagan4599
9 Replies

6. Shell Programming and Scripting

Remove a line from a file

Hi ,guys. I have one question: I want to write a script which removes a line with certain string from a file, for example The name of the file is: "passwd", the contents of it is below: ************************* ... brownj2:x:5000: hynesp:x:5001: leeb:x:5002 dioxna:x:5003 ... ... (2 Replies)
Discussion started by: daikeyang
2 Replies

7. UNIX for Dummies Questions & Answers

remove a line within a file

Hi all, i have a text file similar to belowA1 A2 A3 B1 ... .... *** # first occurance B1 ... .... *** # second occurance B1 ... .... *** # third occurance My desired output is B1 ... .... *** # second occurance B1 ... .... *** # third occurance I want to remove the first line that is after... (3 Replies)
Discussion started by: new2ss
3 Replies

8. Shell Programming and Scripting

How to remove last line of the file

hi sir, i need help..how to remove last line of the each file for example i have files a.txt ,b.txt and so on..i wanted to delete last list of each file..the patten not same for each file..any help? thanks in advance (3 Replies)
Discussion started by: mani_um
3 Replies

9. Shell Programming and Scripting

Remove header(first line) and trailer(last line) in ANY given file

Hi, I need some help in removing the header (first line) and the trailer (last line) in a give file... The data file actually comes in EBCDIC format and I converted it into ASCII.. Now I need to strip off the first line and the last line.. I think we can use sed to do something like this:... (2 Replies)
Discussion started by: madhunk
2 Replies

Featured Tech Videos