LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 01: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, 01:54 PM   #2
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 133Reputation: 133
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 02:50 PM. Reason: corrected code. thanks to sycamorex :)
 
Old 01-24-2012, 02:24 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
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, 02: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 06:29 PM.
 
Old 01-24-2012, 02:26 PM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
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, 02:54 PM   #6
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 133Reputation: 133
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, 07:26 AM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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 07:58 AM
unpredictable "delete" "move to trash" or "cut" file menu option dorianrenato Linux - General 3 11-28-2011 07:41 PM
[SOLVED] "Insert" & "Delete" key returns "~" in a terminal. sharky Linux - General 15 04-26-2011 09: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 04:50 AM
bash - how to remove lines from "FILE_A" which presents in "FILE_B" ? Vilmerok Programming 4 03-13-2009 05:27 AM


All times are GMT -5. The time now is 11: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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration