LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [bash] remove lines from a file (https://www.linuxquestions.org/questions/programming-9/%5Bbash%5D-remove-lines-from-a-file-160058/)

Drimo 03-19-2004 09:34 PM

[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.

irish_rover 03-19-2004 11:39 PM

Something like this...


#!/bin/bash

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

tail -n $NTMP filename

Drimo 03-20-2004 12:27 AM

Hey cool, that did it!
I will post a working script tomorrow.

Thanks a lot for your help irish_rover; I really appreciate it!

Drimo 03-20-2004 11:16 AM

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


All times are GMT -5. The time now is 02:57 PM.