LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-18-2008, 08:05 AM   #16
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682

A) for var test. This probably won't work. Do you want
for var in $(cat test)

Also, test is a bad name to use because it is the name of a builtin. This is especially true if you tried to use test as the name of a file or alias.

Also, you are matching lines that contain the characters of the number and not deleting that line itself.

If you want to delete a particular line in sed;
sed -i "${line}d" file

If $line is 3, this will be evaluated as:
sed -i 3d file
 
Old 05-18-2008, 08:05 AM   #17
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by SBN View Post
What does the code do?
It does exactly what it says it does!!! Seriously, what part do you not understand?

In addition to the documentation already suggested, my favorite SED tutorial is here: http://www.grymoire.com/Unix/Sed.html

The thing that might be hard to see is the use of a "backreference". Here is a generic example:

sed 's/stuff\(keepthis\)morestuff/ newstuff\1/'
The output of this will be: "keepthis newstuff". Anything between the escaped parentheses ("\(\)") is inserted where the "\1" appears.
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed: print section of file from string to end of file samyboy Linux - Newbie 4 02-26-2008 07:23 AM
read-only file system error when editing a config file smallfrowne Linux - Newbie 5 02-19-2008 06:06 PM
editing a very large HTML file (or, extracting URLs from a file) Chriswaterguy Linux - Software 3 11-27-2007 06:07 PM
filesize limit on 'cat $file | sed > $file' drkstr Linux - Software 2 07-10-2006 02:47 AM
multiple file editing using... sed? perl? bpk Linux - Software 2 10-07-2005 04:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:04 PM.

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