Replace string at begining of the line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replace string at begining of the line
# 1  
Old 04-10-2016
Replace string at begining of the line

Hello again people,

I have a list of websites in this format:

Code:
domain.com
domain1.com
domain2.com
domainwww.com
domain2www.com
domain3www.com
www.domain.com
www.domain2.com
www.domain3.com

I want to replace the string "www." with "nothing" but only lines that start with "www."

Thank you.
# 2  
Old 04-10-2016
What haveyou tried? Do you know about regular expressions: hint '^www\.' would locate what string?
# 3  
Old 04-10-2016
Hah that worked... I tried it with
Quote:
instead of
Quote:
---------- Post updated at 12:17 PM ---------- Previous update was at 11:54 AM ----------

Actually it doesnt work.. tested now..

Output from nano:

Code:
[ "'^www\.'" not found ]

Code:
sed 's/'^www/.'//g' dom1 >> dom3

I dont think I got this right..


Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 04-10-2016 at 02:32 PM.. Reason: Added code tags
# 4  
Old 04-10-2016
There's too many ' in the sed command, and jim mcnamara posted the dot correctly escaped.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

2. Shell Programming and Scripting

Read line by line and replace string.

Hi, I currently have a problem that I need to read a file line by line. After I read it line by line there are some commands in which I have to change a specific string.(In my case, I have to make a script that changes all the passwords into hash value) Here is a sample input... (3 Replies)
Discussion started by: thebennnn
3 Replies

3. Emergency UNIX and Linux Support

Find a line using a condition and replace a string in that line

Hello, I have a 100 line code. I have given a sample of it below: ABC*654654*1*54.54*21.2*87*1*654654654654 CCC*FS*FS*SFD*DSF GGG*FGH*CGB*FBDFG*FGDG ABC*654654*1*57.84*45.4*88*2*6546546545 CCC*WSF*SG*FGH*GHJ ADA*AF*SFG*DFGH*FGH*FGTH I need to select the line starting with "ABC" its... (3 Replies)
Discussion started by: nithins007
3 Replies

4. Shell Programming and Scripting

Find a line using a condition and replace a string in that line

Hello, I have a 100 line code. I have given a sample of it below: ABC*654654*1*54.54*21.2*87*1*654654654654 CCC*FS*FS*SFD*DSF GGG*FGH*CGB*FBDFG*FGDG ABC*654654*1*57.84*45.4*88*2*6546546545 CCC*WSF*SG*FGH*GHJ ADA*AF*SFG*DFGH*FGH*FGTH I need to select the line starting with "ABC" its... (6 Replies)
Discussion started by: nithins007
6 Replies

5. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

6. UNIX for Advanced & Expert Users

junk characters in the begining of every line

Hi Experts, here is a background to my problem : I am exporting data from teradata using fastexport utility, as varchar data. This pads additional two bytes (2 places as seen in notepad) in the resultset. I have found out other means of avoiding it but can't use varchar option in that... (5 Replies)
Discussion started by: sumoka
5 Replies

7. UNIX Desktop Questions & Answers

matching 3 digits at the begining and the end of the line

I have a file with hundreds of records and I need to find those records that have three digits at the beginning and the same three digits at the end. $GREP '\(\)\(\)\(\)\3\2\1'I believe this is part of the script but I am not sure how to compare these 3 digits with the 3 digits at the end of... (2 Replies)
Discussion started by: bartsimpsong
2 Replies

8. Red Hat

How to replace a particular string in a line

I have a file with has the following data abaddda;;;;;;;;asdfd;;;d;dadfewdff;f;v;v;v;;v;v;v;v;v;v;v;w;; ;frf;r;v;afd;f;ad;f;d;;va;;g;g;sd;a;dg;ag;ads;ga;dga;d;dsa;;;; ;;sd;df;asd;f;df;adf;adf;;df;df;;d;f;f;sf;df;f;df;;fd;f;f;sdfd;;;; I want to replace every 13 th semicolon ; in... (1 Reply)
Discussion started by: Raju Datla
1 Replies

9. Shell Programming and Scripting

search for a string ,replace the whole line with new line

hai i am very new to unix. i am having two files like this. first.properties cache.ZA.TL_CCY=SELECT trim(CCY_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS... (4 Replies)
Discussion started by: kkraja
4 Replies

10. Shell Programming and Scripting

delete blank space in begining of line

Hi All, below is my data file file.txt $$0 ServerA LAN1 AAA IT01 04/30/2008 09:16:26 $$0 ServerB LAN1 AAA IT02 04/30/2008 09:16:26 here $ is a blank space how to delete first 2 blank spaces in a file. (4 Replies)
Discussion started by: karthikn7974
4 Replies
Login or Register to Ask a Question