LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 07-14-2003, 11:46 PM   #1
marco271
LQ Newbie
 
Registered: Feb 2003
Posts: 6

Rep: Reputation: 0
Bash


What command can I use in order to delete a line from a regular file?

I use >> to append a line to a file but how can I delete any line from the same file?

Thanks,

marco271
 
Old 07-15-2003, 12:12 AM   #2
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
while it's true you can use a command such as 'echo something >> file.txt' to append a line I'm afraid removal is a little more complicated (not by much though.)

take a look at tools such as sed, awk, and the like.

I've only begun using sed... however something like
sed -e 's/^<pattern to replace>$//' filename.txt
should work.
 
Old 07-15-2003, 12:42 AM   #3
marco271
LQ Newbie
 
Registered: Feb 2003
Posts: 6

Original Poster
Rep: Reputation: 0
I would like to try to use only the bash shell.
Do you think there is a way?
 
Old 07-15-2003, 03:57 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
sed *IS* only using bash shell...
 
Old 07-15-2003, 08:23 AM   #5
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
marco271, you could even make it look more like a simple command by defining a function in your bash environment (by way of the .bashrc file)

in .bashrc define the following

delline () {
sed -e "s/$1//" $2
}

then from the command line you could execute:
delline some_text textfile.txt
 
Old 07-15-2003, 03:28 PM   #6
marco271
LQ Newbie
 
Registered: Feb 2003
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for your help!
 
Old 07-19-2003, 04:30 PM   #7
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
no problem
 
  


Reply



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
$LINENO can't be modified in bash 3.0, while it can be in bash 2.05b Darwish Linux - Software 1 11-07-2005 02:57 PM
bash my little bash alaios Linux - Newbie 4 01-10-2005 11:59 PM
bash + html + javascript or just bash ? rblampain Programming 4 12-01-2004 07:53 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM
Bash Half_Elf Linux - General 2 05-01-2002 06:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:10 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration