LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 10-25-2003, 09:58 PM   #1
rche3252
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???

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

Rep: Reputation: 79
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, 08:17 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

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

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

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

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, 08:16 AM   #6
karthi_27
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Rep: Reputation: 0
Thumbs up

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

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

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


Reply


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 57 04-17-2016 07:07 PM
Shell Script to Delete line if pattern exists topcat Programming 22 08-23-2011 05:58 AM
Extracting the line number in Unix Shell? Aziz Programming 2 12-01-2004 12:03 PM
Shell script - how to show a specific line of a text file davi_cabral Linux - Software 3 09-28-2004 02:39 PM
How to delete a line from a text file with shell script programming Bassam General 1 01-28-2004 09:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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