Visit Jeremy's Blog.
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 03-19-2004, 09:34 PM   #1
LQ Newbie
Registered: Aug 2003
Posts: 11

Rep: Reputation: 0
[bash] remove lines from a file

I am trying to write a script to generate a menu for XFce4 on the fly when I login.

My goal is to generate a menu using Menu Maker and append that to a base menu I have created. The problem with appending is that the automatically generated file, menuAuto.xml, has tags that prevent the resulting menu file from being a valid menu.

I figure that if I wrote some script to remove the first 3 lines from menuAuto.xml, the append will work correctly.

What code is necessary for a bash script to remove the first 3 lines from a file?

Thanks in advance! I think this will be a neat little script once it is finished.
Old 03-19-2004, 11:39 PM   #2
Registered: Sep 2002
Location: IN, USA
Distribution: Debian, Endian FW
Posts: 368

Rep: Reputation: 30
Something like this...


MTMP=`wc -l long | awk '{print $1}'`
NTMP=`expr $MTMP - 3`

tail -n $NTMP filename
Old 03-20-2004, 12:27 AM   #3
LQ Newbie
Registered: Aug 2003
Posts: 11

Original Poster
Rep: Reputation: 0
Hey cool, that did it!
I will post a working script tomorrow.

Thanks a lot for your help irish_rover; I really appreciate it!
Old 03-20-2004, 11:16 AM   #4
LQ Newbie
Registered: Aug 2003
Posts: 11

Original Poster
Rep: Reputation: 0
Final script code

Here is the final code for this script if anyone is interested.

# remove old menu.xml
rm menu.xml
# generate menuAuto.xml using menumaker
mmaker -o menuAuto.xml XFce4
# remove the first 3 lines of menuAuto.xml
MTMP=`wc -l menuAuto.xml | awk '{print $1}'`
NTMP=`expr $MTMP - 3`
tail -n $NTMP menuAuto.xml > menuAuto2.xml
# append menuAuto.xml onto menuRoot.xml, write to menuTest.xml
cat menuRoot.xml menuAuto2.xml > menu.xml
# remove menuAuto files
rm menuAuto.xml menuAuto2.xml
Menu Maker can be found at


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
Remove odd lines from a text file Mr. Gone Programming 2 09-19-2005 11:16 AM
How to remove lines from a file doza Linux - General 2 04-27-2005 11:59 AM
Can't get lines of a file with a Bash script.. barisdemiray Programming 2 08-11-2004 12:42 PM
remove identical lines in a file benjithegreat98 Linux - General 4 04-24-2004 06:12 AM
How do i remove blank lines from a file? kakho Programming 1 04-15-2004 03:57 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:45 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