The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Trying to remove single character from a line Iz3k34l UNIX for Dummies Questions & Answers 5 07-07-2007 01:29 PM
Vi single character change Brett Taylor Shell Programming and Scripting 6 08-30-2006 02:07 PM
wildcard abhi UNIX for Dummies Questions & Answers 13 02-15-2005 01:43 AM
reading a single character in C alodha High Level Programming 3 01-28-2005 06:22 AM
Find wildcard .shtml files in wildcard directories and removing them- How's it done? Neko UNIX for Dummies Questions & Answers 1 06-27-2001 09:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-15-2006
stevefox stevefox is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 115
Question Single character wildcard for SED

Could someone tell me the single character wildcard for SED?

I have the file below:

Code:
$ more input2
AAA /A/B/C BBB /D/E/F
CCC /G/H/I DDD
I want to remove all strings which contain forward slashs "/" to get the below:

AAA BBB
CCC


I tried to do it in SED by the command below but I couldn't find out the single character wildcard and failed.

$ sed "s/\/.*\/?//g" input3

If there's an awk solution to the above please tell me as well.

Any help will be appreciated.
  #2 (permalink)  
Old 02-15-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Code:
 sed -e 's#/.##g' input.txt
  #3 (permalink)  
Old 02-15-2006
stevefox stevefox is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 115
Smile

Thank you vino for your quick response!
By the way is there a manual/reference for the use of 's#/.##g' command?
  #4 (permalink)  
Old 02-15-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by stevefox
Thank you vino for your quick response!
By the way is there a manual/reference for the use of 's#/.##g' command?
Yups. See man sed.

If you are talking about the #, then see info sed. If you dont have info sed, this is what it says

Code:
The `s' Command
===============

   The syntax of the `s' (as in substitute) command is
`s/REGEXP/REPLACEMENT/FLAGS'.  The `/' characters may be uniformly
replaced by any other single character within any given `s' command.
The `/' character (or whatever other character is used in its stead)
can appear in the REGEXP or REPLACEMENT only if it is preceded by a `\'
character.
  #5 (permalink)  
Old 02-15-2006
stevefox stevefox is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 115
Question

Thanks vino.
I understood how the command worked.
But it only works for removing strings with a fixed number of characters after the forward slash.

If I had an input with unfixed number of characters after the forward slash like below:

Code:
$ more input2
AAA /aaa/B/C BBB /D/E/ff
CCC /D/eeee/F DDD
How can I remove all strings which contain forward slashs "/" to get the below:

AAA BBB
CCC DDD
  #6 (permalink)  
Old 02-15-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
Code:
awk '
{ 
for (i=1; i<= NF; i++ ) 
{
if ( $i !~ /\// ) 
	{ 
	printf $i" "
	} 
}
printf "\n"
}' file
  #7 (permalink)  
Old 02-15-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Code:
sed -e 's#/[^/ ]*##g'
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0