Search and replace data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search and replace data
# 1  
Old 06-05-2013
Search and replace data

FILENAME: (Orig File)
Code:
lab computer11node1 { hardware ok 19:50:56:bd:03:c2; MAC-ADDRESS 10.1.1.1; }
lab computer11node2 { hardware ok 19:50:56:bd:03:c3; MAC-ADDRESS 10.1.1.2; }

FILENAME2:
Code:
computer11node1 11:50:56:81:33:c5
computer11node2 11:50:56:81:33:c6
computer11node3 11:50:56:81:33:c7
computer11node4 11:50:56:81:33:c8

OUTPUT: (desired output)
Code:
lab computer11node1 { hardware ok 11:50:56:81:33:c5; MAC-ADDRESS 10.1.1.1; }
lab computer11node2 { hardware ok 11:50:56:81:33:c6; MAC-ADDRESS 10.1.1.2; }


Last edited by Franklin52; 06-05-2013 at 03:05 AM.. Reason: Please use code tags
# 2  
Old 06-05-2013
Tyr this
Code:
awk 'NR==FNR{a[$1]=$2;next}
a[$2]{$6=a[$2]}1' File2 File1

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 06-05-2013
not working Doug..
# 4  
Old 06-05-2013
Could you please post error message, what you have faced ?
# 5  
Old 06-05-2013
its working..thanks..is there command like in sed, where you can put it w/o creating another file like using sed -i.

somethin like we dont need to redirect.
# 6  
Old 06-05-2013
It's actually most safe to do that in the shell:
Code:
file=/path/to/FILENAME1
cp -p $file $file.bak &&
awk '...' File2 $file.bak > $file

This is the same as perl -i.bak ... would do.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search data file2 for entries in data file1

Hello, I have two data files: file1: 9780205646999 28.31 20 Cengage 9780205647040 51.94 20 Cengage 9780205660568 49.11 20 Cengage 9780205696758 51.75 20 Cengage 9780205727643 41.63 20 Cengage file2: 9780020080954 9780020080954 2 ... (7 Replies)
Discussion started by: palex
7 Replies

2. Shell Programming and Scripting

Nested search in a file and replace the inner search

Hi Team, I am new to unix, please help me in this. I have a file named properties. The content of the file is : ##Mobile props east.url=https://qa.east.corp.com/prop/end west.url=https://qa.west.corp.com/prop/end south.url=https://qa.south.corp.com/prop/end... (2 Replies)
Discussion started by: tolearn
2 Replies

3. Shell Programming and Scripting

awk/sed to search & replace data in first column

Hi All, I need help in manipulating the data in first column in a file. The sample data looks like below, Mon Jul 18 00:32:52 EDT 2011,NULL,UAT Jul 19 2011,NULL,UAT 1] All field in the file are separated by "," 2] File is having weekly data extracted from database 3] For eg.... (8 Replies)
Discussion started by: gr8_usk
8 Replies

4. Shell Programming and Scripting

Using sed to search and replace data

Hi, Kindly need your expertise in this problem. I have to search and replace data. The problem is, the data is in the same format but slightly different content. What I need is sed commands that can work for those "slightly different content". input: ... (3 Replies)
Discussion started by: Alvin123
3 Replies

5. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

6. Shell Programming and Scripting

Replace data of one column with data on other file corresponding to transaction ID matched

Hi All, I have two files one of which having some mobile numbers and corresponding value whose sample content as follows: 9058629605,8.0 9122828964,30.0 And in second file complete details of all mobile numbers and sample content as follows and delimeter used is comma(,): ... (8 Replies)
Discussion started by: poweroflinux
8 Replies

7. Shell Programming and Scripting

search and replace with data from another file

Can someone help me in solving the problem below. I have the following two files template_file ------------ ...other data.. ...other data.. FILE_NAME= ...other data.. ...other data.. list_file ---------- <file_name1> <file_name2> <file_name3> I need to produce another output... (3 Replies)
Discussion started by: paruthiveeran
3 Replies

8. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

10. Shell Programming and Scripting

search and replace dynamic data in a shell script

Hi, I have a file that looks something like this: ... 0,6,256,87,0,0,0,1187443420 0,6,438,37,0,0,0,1187443380 0,2,0,0,0,10,0,1197140320 0,3,0,0,0,10,0,1197140875 0,2,0,0,0,23,0,1197140332 0,3,0,0,0,23,0,1197140437 0,2,0,0,0,17,0,1197140447 0,3,0,0,0,17,0,1197140543... (8 Replies)
Discussion started by: csejl
8 Replies
Login or Register to Ask a Question