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
 
LinkBack Search this Thread
Old 03-19-2004, 09:34 PM   #1
Drimo
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
irish_rover
Member
 
Registered: Sep 2002
Location: IN, USA
Distribution: Debian, Endian FW
Posts: 368

Rep: Reputation: 30
Something like this...


#!/bin/bash

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

tail -n $NTMP filename
 
Old 03-20-2004, 12:27 AM   #3
Drimo
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
Drimo
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.

Code:
#!/bin/bash
                                                                                
# 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 http://menumaker.sourceforge.net/node1.html
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


All times are GMT -5. The time now is 10:48 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration