Single character wildcard for SED


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Single character wildcard for SED
# 1  
Old 02-15-2006
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  
Old 02-15-2006
Code:
 sed -e 's#/.##g' input.txt

# 3  
Old 02-15-2006
Bug

Thank you vino for your quick response!
By the way is there a manual/reference for the use of 's#/.##g' command?
# 4  
Old 02-15-2006
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  
Old 02-15-2006
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  
Old 02-15-2006
Code:
awk '
{ 
for (i=1; i<= NF; i++ ) 
{
if ( $i !~ /\// ) 
	{ 
	printf $i" "
	} 
}
printf "\n"
}' file

# 7  
Old 02-15-2006
Code:
sed -e 's#/[^/ ]*##g'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to repeat a character in a field if it's a single character?

I have a csv dataset like this : C,rs18768 G,rs13785 GA,rs1065 G,rs1801279 T,rs9274407 A,rs730012 I'm thinking of use like awk, sed to covert the dataset to this format: (if it's two character, then keep the same) CC,rs18768 GG,rs13785 GA,rs1065 GG,rs1801279 TT,rs9274407... (7 Replies)
Discussion started by: nengcheng
7 Replies

2. Shell Programming and Scripting

WildCard character - not able to understand

Hello, I have one script which looks as given below , . ${0%/*}/init && init_job || exit 1 what I understood is , 1. above syntax has three commands, two on left of || and one on right of ||. 2. ${0%/*} would generate some path. Question. A. What is the meaning of ${0%/*} ,... (2 Replies)
Discussion started by: ParthThakkar
2 Replies

3. Shell Programming and Scripting

sed using wildcard

Hi Folks, I had a requirement to replace a pattern a.*a with 'a' alone. I'm writing a sed command to do that. But I'm not able to work this out. Pls help me. echo 'a123a456a789' | sed 's/a.*a/a/' Expected o/p : a456a789 But actual o/p is a789. :confused: how can write that... (6 Replies)
Discussion started by: poova
6 Replies

4. Shell Programming and Scripting

Sed Wildcard

Hello, I apologize for asking what is probably a simple question but I have been unable to understand the other posts on the topic. I have a file that has the following several lines: ABC DEF GH:IJKLMNOP_QRS_TUV_11112012_ABCL5 ABC DEF GH:IJKLMNOP_QRS_TUV_11112013_ABCL4 ABC DEF... (4 Replies)
Discussion started by: MolecularToast
4 Replies

5. UNIX Desktop Questions & Answers

How to squeeze multiple pipe character '|' into single '|' using sed?

Hi, I am trying to convert multiple Unix pipe symbol or bar into single |. I have tried with the following sed statements, but, no success :(. I need it using sed only echo "sed 's/\|\+/\|/g' sed 's/*/\|/' sed 's/\|*/|/' sed -r 's/\|+/\|/' However, the below awk code is working fine.... (4 Replies)
Discussion started by: royalibrahim
4 Replies

6. Shell Programming and Scripting

Replace multiple occurances of same character with a single character.

Hi all, Greetings, I have the following scenario, The contents of main file are like : Unix|||||forum|||||||||||||||is||||||the||best so||||||be|||||on||||||||||||||||||||||||||||||||||||||||||||it And i need the output in the following form: Unix=forum=is=the=best so=be=on=it ... (3 Replies)
Discussion started by: dipanchandra
3 Replies

7. UNIX for Dummies Questions & Answers

how to search and list file with wildcard character

hi, I want to search all files in the current working direcotry and to print in comma (,) seperated output. But I have two patterns to search for. Files will be in ABC20100508.DAT format. Search should happen on the format (ABC????????.DAT) along with date(20100508). I can do a ls... (2 Replies)
Discussion started by: anandapani
2 Replies

8. UNIX for Advanced & Expert Users

Unix wildcard character question

1. Is . wildcard? , the documented wildcard are "*", "?", and "" . seems mean everything, the follwing cmd will copy everything cp -r /tmp/test1/. /tmp/test2/ However it doesn't work for rm, why? $ ls -a . .. .a .aa aa t2 $ rm -rf . $ ls -a . .. .a .aa ... (3 Replies)
Discussion started by: honglus
3 Replies

9. Shell Programming and Scripting

Matching multiples of a single character using sed and awk

Hi, I have a file 'imei_01.txt' having the following contents: $ cat imei_01.txt a123456 bbr22135 yet223 where I want to check whether the expression 'first single alphabet followed by 6 digits' is present in the file (here it is the first record 'a123456') I am using the following... (5 Replies)
Discussion started by: royalibrahim
5 Replies

10. Shell Programming and Scripting

sed help/wildcard substitution

I need to perform the following substitutions and have been struggling to determine if or how I can do this with sed or perl. I need to change the string foo(bar) to moo(bar,0) wherever this occurs in a file. Is there a way to do this? I'm thinking there might be a wildcard of some sort that... (4 Replies)
Discussion started by: Mike@NZ
4 Replies
Login or Register to Ask a Question