Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 27th October 2005, 11:13 AM
panpol Offline
Registered User
 
Join Date: Oct 2005
Posts: 8
Delete lines from a file

Hi,
I have a file with 2 numbers, for example:

215
816

Can I use the numbers of this file, to delete some lines of one other file with the use of sed,awk,…?Is there a way to pass this numbers as parameters to sed or awk and delete the lines from 215 to 816 of one other file?

Thanks
Reply With Quote
  #2  
Old 27th October 2005, 12:40 PM
brahms Offline
Registered User
 
Join Date: Aug 2004
Posts: 434
Code:
!/bin/sh

LINES=( $( cat filewith2numbers ) )
STARTLINE=${LINES[0]}
ENDLINE=${LINES[1]}

sed -e '${STARTLINE},${ENDLINE}d' otherfile
__________________
:cool:
Reply With Quote
  #3  
Old 27th October 2005, 12:40 PM
twelvegates Offline
Registered User
 
Join Date: Aug 2005
Posts: 48
Code:
topln=`head -1 linefile`
bottomln=`tail -1 linefile`
ed - targetfile <<+++
${topln},${bottomln}d
w
q
+++
done

Last edited by twelvegates; 27th October 2005 at 12:45 PM.
Reply With Quote
  #4  
Old 27th October 2005, 04:46 PM
homey Offline
Registered User
 
Join Date: Feb 2005
Posts: 415
Maybe something like this.
Code:
#!/bin/bash

list="/home/list.txt"
file="/home/file.txt"
n=0
for i in `cat ${list}` ; do
   str=${str}${i},
   let n=${n}+1
if [ "$n" -gt "2" ] ; then
   echo "You said a file with two numbers"
   exit 0
fi
   num=`echo $str | sed 's/,$//g'`
done
sed -e $num'd' $file
echo
Reply With Quote
Reply

Tags
delete, file, lines

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to Remove few lines from a file fed.linuxgossip Using Fedora 3 5th March 2007 09:46 PM
Command to Remove last 5 lines in a file fed.linuxgossip Using Fedora 3 4th March 2007 09:06 PM
Automatic type text , delete file and save file problem shown in FC3 and FC2 kalpana EOL (End Of Life) Versions 1 10th June 2005 04:50 AM


Current GMT-time: 10:44 (Saturday, 25-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat