Yagami
July 24, 2009, 3:38am
1
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
pludi
July 24, 2009, 3:52am
2
You can use sed with in-place editing:
sed -i -e '1,100d' file
Yagami
July 24, 2009, 5:52am
3
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 Solaris:confused:
Any idea about solaris??
Appretiate your help
pludi
July 24, 2009, 6:05am
4
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:
perl -i -ne 'print if $.>100' file
Yagami
July 24, 2009, 6:25am
5
Thank you !!
It worked fine
Appretiate you quick response:b:
A solution using awk, just to make the group complete
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.
Let's not forget about:
d100d
in Vi.
Note: Yes, I do know the OP did not want to actually open the file. Just putting it out there for the archives.