SED Question: Search and Replace start of line to matching pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED Question: Search and Replace start of line to matching pattern
# 1  
Old 03-17-2010
SED Question: Search and Replace start of line to matching pattern

Hi guys,

got a problem here with sed on the command line.

If i have a string as below:
Code:
online     xx:wer:xcv:  sdf:/asdf/http:https-asdfd

How can i match the pattern "http:" and replace the start of the string to the pattern with null?

I tried the following but it doesn't work:
Code:
 cat /tmp/test | sed 's/*http\://g'


TIA
# 2  
Old 03-17-2010
Lose the cat. Let sed open the file - try this:
Code:
sed 's/^.*http\://g'  filename > newfilename

# 3  
Old 03-18-2010
Quote:
Originally Posted by DrivesMeCrazy
Hi guys,

got a problem here with sed on the command line.

If i have a string as below:
Code:
online     xx:wer:xcv:  sdf:/asdf/http:https-asdfd

How can i match the pattern "http:" and replace the start of the string to the pattern with null?

I tried the following but it doesn't work:
Code:
 cat /tmp/test | sed 's/*http\://g'

TIA

You did some mistake in your code. Because in the regular expression you are not match correctly. The following code will give the correct answer
Code:
cat filename |   sed 's/.*http\://g'

or use the following code
Code:
 
 sed 's/.*http\://g' filename

# 4  
Old 03-18-2010
Thanks alot Jim.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - Exact pattern matching and replace

Hi Team, I am facing a problem as under, Suppose I have a file (test.txt) with the below content (all braces and slashes are included in the contents of the file) Now I want to append few words below matched line, I have written the below sed: sed '/option/a insert text here' test... (2 Replies)
Discussion started by: ankur328
2 Replies

2. Shell Programming and Scripting

sed - Search and replace within pattern

Hi Guys! Unix newbie here! Have a requirement for which I have been scouting the forums for a solution but has been out of luck so far :( I have a file which contains the following:- TEST1|TEST2|"TEST3|1@!2"|TEST5 My sed command should result in either one the following output:-... (6 Replies)
Discussion started by: hishamzz
6 Replies

3. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

4. UNIX for Dummies Questions & Answers

Sed: Adding new line after matching pattern

Hi I just wanted to add a new line after every matching pattern: The method doing this doesn't matter, however, I have been using sed and this is what I tried doing, knowing that I am a bit off: sed 'Wf a\'/n'/g' Basically, I want to add a new line after occurrence of Wf. After the line Wf... (5 Replies)
Discussion started by: MIA651
5 Replies

5. Shell Programming and Scripting

sed to replace the matching pattern with equal number of spaces

Hi I have written a shell script which used sed code below sed -i 's/'"$Pattern"'/ /g' $FileName I want to count the length of Pattern and replace it with equal number of spaces in the FileName. I have used $(#pattern) to get the length but could not understand how to replace... (8 Replies)
Discussion started by: rakeshkumar
8 Replies

6. Shell Programming and Scripting

How to use sed to modify a line above or below matching pattern?

I couldn't figure out how to use sed or any other shell to do the following. Can anyone help? Thanks. If seeing a string (e.g., TODAY) in the line, replace a string in the line above (e.g, replace "Raining" with "Sunny") and replace a string in the line below (e.g., replace "Reading" with... (7 Replies)
Discussion started by: sprinner
7 Replies

7. Shell Programming and Scripting

sed pattern matching question

I inherited a script that contains the following sed command: sed -n -e '/^.*ABCD|/p' $fileName | sed -e 's/^.*ABCD|//' | sed -e 's/|ABCD$//' > ${fileName}.tmp What I'm wondering is whether ABCD has a special pattern matching value in sed, such as a character class similar or identical to . ... (9 Replies)
Discussion started by: topmhat
9 Replies

8. Shell Programming and Scripting

search a pattern and replace the whole line

Hi All, I have a requirement where I have to find a pattern in a file and comment the whole line containing the search pattern. Any ideas in shell is welcome. Thanks in advance, Regards, Arun (3 Replies)
Discussion started by: arun_maffy
3 Replies

9. Shell Programming and Scripting

sed: Find start of pattern and extract text to end of line, including the pattern

This is my first post, please be nice. I have tried to google and read different tutorials. The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies

10. Shell Programming and Scripting

SED Search Pattern and Replace with the Pattern

Hello All, I have a string "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031", and I just want to extract LLSV1, but I dont get the expected result when using the sed command below. # echo "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031" | awk '{print... (4 Replies)
Discussion started by: racbern
4 Replies
Login or Register to Ask a Question