Replacing urls from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing urls from file
# 1  
Old 11-04-2014
Replacing urls from file

Hi ALL,

I have a file A which contains

Code:
A=www.google.com
B=www.abcd.com
C=www.nick.com
D=567

file B Contains

Code:
A=www.google1234.com
B=www.bacd.com
C=www.mick.com
D=789


I wanted a script which can replace file A contents with B Contents
# 2  
Old 11-04-2014
Hi,

I may be missing some thing here, why not just copy file B to file A?

Regards

Dave
# 3  
Old 11-04-2014
He he Smilie

There are some other contents as well in my file, So I can't replace all of the contents.
# 4  
Old 11-05-2014
To be more clear and specific

Code:
A=www.google.com
B=www.abcd.com
C=www.nick.com
D=567
E=89000
F=www.sneh.com

and i would want it to replace only those contents which are present below

Code:
A=www.google1234.com
B=www.bacd.com
C=www.mick.com
D=789


can anyone plz help?
# 5  
Old 11-06-2014
Hello Nikhil,

Following may help you in same. Let's say we have files as follows.

FileA is as follows.
Code:
A=www.google.com
B=www.abcd.com
C=www.nick.com
D=567
E=umma.com
F=char.com

FileB is as follows.
Code:
A=www.google1234.com
B=www.bacd.com
C=www.mick.com
D=789
Q=queen

Then following may help you in same.

Code:
awk -F"=" 'FNR==NR{A[$1]=$2;next} ($1 in A){print $1 OFS A[$1]} !($1 in A){print $0}' FileA OFS="=" FileB

Output will be as follows.
Code:
A=www.google.com
B=www.abcd.com
C=www.nick.com
D=567
Q=queen

It will replace all the contents which are present in FileA but if any content from FileB is not present in FileA it will keep it as it is.

Hope this helps.


Thanks,
R. Singh
# 6  
Old 11-06-2014
I'd guess he/she wants it more like
Code:
awk 'FNR==NR{R[$1]=$0;next} $1 in R {$0=R[$1]} 1' FS="=" OFS="=" file2 file1
A=www.google1234.com
B=www.bacd.com
C=www.mick.com
D=789
E=89000
F=www.sneh.com

?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regex for URLs and files

Hi, I am looking for a regex that will validate a URL and files accessed in a browser. For example:http://www.google.co.uk http://www.google.com https://www.google.co.uk https://www.google.com ftp:// file:///somefile/on/a/server/accessed/from/browser/file.txt So far I have: ... (4 Replies)
Discussion started by: muay_tb
4 Replies

2. Shell Programming and Scripting

Replacing 12 columns of one file by second file based on mapping in third file

i have a real data prod file with 80+ fields containing 1k -2k records. i have to extract say 12 columns out of this which are sensitive fields along with one primary key say SEQ_ID (like DOB,account no, name, SEQ_ID, govtid etc) in a lookup file. i have to replace these sensitive fields in... (11 Replies)
Discussion started by: megh12
11 Replies

3. Post Here to Contact Site Administrators and Moderators

Not allowed to post URLs

Hi, I tried to post some perl code for discussion (wrapped in swaddling . However, a regex has an escaped backslash so the forum parser sees it as an URL? Had the same experience with the sample data that I tried to provide for the same discussion. It contains emails addresses,... (1 Reply)
Discussion started by: msutfin
1 Replies

4. Web Development

How to redirect URLs in Apache?

I am a total newbie to Apache. I need to do this only for this weekend during an upgrade from old system to new system We have different URLs http://domain.name/xxx (xxx varies to any length and words - it can be /home, /login, /home/daily, /daily/report, etc). How do i redirect all those to... (0 Replies)
Discussion started by: GosarJunk
0 Replies

5. Shell Programming and Scripting

Hashing URLs

So, I am writing a script that will read output from Bulk Extractor (which gathers data based on regular expressions). My script then reads the column that has the URL found, hashes it with MD5, then outputs the URL and hash to a file. Where I am stuck on is that I want to read the bulk... (7 Replies)
Discussion started by: twjolson
7 Replies

6. Homework & Coursework Questions

How is it possible to include URLs within the terminal?

I have noted that Oracle use some kind of hypermarking to create URLs within the terminal on Enterprise Linux. Any idea how to create a URL such as ..., which when right clicked opens a browser window? This supposed to be spam/advertisement? Got a PM from OP; it is not supposed to be spam... (1 Reply)
Discussion started by: jon80
1 Replies

7. Shell Programming and Scripting

Remove external urls from .html file

Hi everyone. I have an html file with lines like so: link href="localFolder/..."> link href="htp://..."> img src="localFolder/..."> img src="htp://..."> I want to remove the links with http in the href and imgs with http in its src. I'm having trouble removing them because there... (4 Replies)
Discussion started by: CowCow339
4 Replies

8. UNIX for Advanced & Expert Users

Parsing a file which contains urls from different sites

Hi I have a file which have millions of urls from different sites. Count of lines are 4000000. http://www.chipchick.com/2009/09/usb_hand_grenade.html http://www.engadget.com/page/5 http://www.mp3raid.com/search/download-mp3/20173/michael_jackson_fall_again_instrumental.html... (2 Replies)
Discussion started by: solitare123
2 Replies

9. UNIX for Dummies Questions & Answers

find and replace urls

I need to archive a large website onto a DVD. Many of the links and image srcs are absolute URLs. As I don't want to alter them all manually, I'm looking for a perl or unix command that would remove: http://www.mydomain.com/mysubfolder/ and replace with: ./ Can anyone help me with this... (3 Replies)
Discussion started by: benkyma
3 Replies
Login or Register to Ask a Question