Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-25-2003, 08:58 PM   #1
LQ Newbie
Registered: Oct 2003
Posts: 2

Rep: Reputation: 0
unix shell script:How to delete the first line in a file??

How to delete the first line in a file???

Old 10-26-2003, 06:48 AM   #2
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
To remove the first line from the file in "$file" then you could use:
tail $file -n`echo \`grep -c '' $file\`-1|bc`
Old 10-26-2003, 07:17 AM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
mv myfile.txt myfile.tmp
sed 1d myfile.tmp > myfile.txt
rm myfile.tmp
Old 03-03-2010, 07:01 AM   #4
Senior Member
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,456
Blog Entries: 6

Rep: Reputation: 51
What if file is busy(say it is a log being accesed?)
Old 03-03-2010, 07:11 AM   #5
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381

I told you already that this cannot be done! (In this, merged, thread).

Also: Did you try the solution I offered at the end of the thread?????

PS: Do _not_ repeat the same question in different forms. This is the third fourth time you ask the same question.
Old 03-03-2010, 07:16 AM   #6
LQ Newbie
Registered: Mar 2010
Posts: 6

Rep: Reputation: 0
Thumbs up

There is no need for script here . just do it using sed,

sed -i 1d file
Old 03-03-2010, 07:32 AM   #7
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 242Reputation: 242Reputation: 242
i noticed this is very old thread, but nonetheless,
more +2 file > newfile


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 55 07-09-2015 12:46 PM
Shell Script to Delete line if pattern exists topcat Programming 22 08-23-2011 04:58 AM
Extracting the line number in Unix Shell? Aziz Programming 2 12-01-2004 11:03 AM
Shell script - how to show a specific line of a text file davi_cabral Linux - Software 3 09-28-2004 01:39 PM
How to delete a line from a text file with shell script programming Bassam General 1 01-28-2004 08:51 PM

All times are GMT -5. The time now is 11:46 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration