LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-24-2012, 12:44 PM   #1
linuxon
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Rep: Reputation: Disabled
how to delete the lines containing "./."


Hello everyone,

I am new to linux, I know how to delete the one special character in linux, but i don't know how to delete the lines containing character like "./.". hopefully someone could give some instruction.

Thanks a lot
 
Old 01-24-2012, 12:54 PM   #2
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 134Reputation: 134
This will preview the changes.
Code:
sed '/\.\/\./d' name_of_your_file
This will create a new file with the changes. Original file will remain as is.
Code:
sed '/\.\/\./d' name_of_your_file > new_file
This will edit the original file
Code:
sed -i '/\.\/\./d' name_of_your_file

Last edited by kabamaru; 01-24-2012 at 01:50 PM. Reason: corrected code. thanks to sycamorex :)
 
Old 01-24-2012, 01:24 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Quote:
Originally Posted by kabamaru View Post
This will preview the changes.
Code:
sed '/.\/./d' name_of_your_file
This will create a new file with the changes. Original file will remain as is.
Code:
sed '/.\/./d' name_of_your_file > new_file
This will edit the original file
Code:
sed -i '/.\/./d' name_of_your_file
The above code will delete any line containing /
Not only ./.

You'd have to escape . as well:

Code:
sed '/\.\/\./d' file
 
Old 01-24-2012, 01:24 PM   #4
linuxon
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks a lot, kabamaru, looks like the last one works

Last edited by linuxon; 01-24-2012 at 05:29 PM.
 
Old 01-24-2012, 01:26 PM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Quote:
Originally Posted by linuxon View Post
Thanks kabamaru, that deleted everything in the file when I tried it. Is there any other way?
See my code above.
 
Old 01-24-2012, 01:54 PM   #6
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 134Reputation: 134
Quote:
Originally Posted by sycamorex View Post
The above code will delete any line containing /
Not only ./.

You'd have to escape . as well:

Code:
sed '/\.\/\./d' file
You're right. The funny thing is I wrote it correctly in my terminal, then wrote it 3 times wrong in the post :-/
 
Old 01-25-2012, 06:26 AM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
To get around conflicts with "/" in sed, you can use a different delimiter.

In the substitution command, you can simply use any ascii character (except for newline and null) instead of the slash. I generally like to use "|" myself.

Code:
sed 's|.*\./\..*||' file	#for demonstration purposes, it leaves a blank line behind
You can also change the delimiter for the address fields, except that you must precede the first delimiter with a backslash.

Code:
sed '\|\./\.|d' file
Finally, instead of backslash-escaping regex-reserved characters, consider using character class brackets instead. This can often make things more readable, as well as being more proper regex syntax.

Code:
sed '\|[.]/[.]|d' file
Here are a few useful sed references.
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/grabbag/
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt

A couple of regular expressions tutorials:
http://mywiki.wooledge.org/RegularExpression
http://www.grymoire.com/Unix/Regular.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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
unpredictable "delete" "move to trash" or "cut" file menu option dorianrenato Linux - General 3 11-28-2011 06:41 PM
[SOLVED] "Insert" & "Delete" key returns "~" in a terminal. sharky Linux - General 15 04-26-2011 08:36 AM
LXer: Alternative To The "200 Lines Kernel Patch That Does Wonders" Which You Can Use Right Away LXer Syndicated Linux News 0 11-19-2010 03:50 AM
bash - how to remove lines from "FILE_A" which presents in "FILE_B" ? Vilmerok Programming 4 03-13-2009 04:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:44 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