Computing.Net > Forums > Linux > Removing top 3 lines from text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Removing top 3 lines from text file

Reply to Message Icon

Name: andrewgrimble
Date: March 27, 2007 at 10:43:22 Pacific
OS: UNIX
CPU/Ram: UNKNOWN
Product: Solaris
Comment:

Hi,

Can anyone tell me how I can remove the top 3 lines from a text file using unix shell scripting. I've been using the korn shell but can't work out how to do it.

Cheers,
Andy




Sponsored Link
Ads by Google

Response Number 1
Name: farmerjoe
Date: March 27, 2007 at 11:44:26 Pacific
Reply:

You need to use Sed. Google is your friend.


0

Response Number 2
Name: BiTByte
Date: March 27, 2007 at 15:56:19 Pacific
Reply:

hi,
maybe my script will help you

-- cut here -----
#!/bin/sh

#get lines of the file
lines=$(grep -c "" $1)

#sub 3
li=$(($lines-3))

#print lines except first three
tail -n $li $1

-- cut here -----

first parameter is the filename to cut the first 3 lines

example (script is called cutfirst3.sh):

sh cutfirst3.sh textfile.txt > newtextfile.txt

in the "newtextfile.txt" the first 3 lines are removed


regards



0

Response Number 3
Name: nails
Date: March 27, 2007 at 18:36:46 Pacific
Reply:

sed '1,3d' mydata > newfile


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Removing top 3 lines from text file

How to read 1 line from text file www.computing.net/answers/linux/how-to-read-1-line-from-text-file/15725.html

Replacing a line in a text file www.computing.net/answers/linux/replacing-a-line-in-a-text-file/30202.html

Replace text from all files www.computing.net/answers/linux/replace-text-from-all-files/21296.html