Search - lookup - replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search - lookup - replace
# 1  
Old 10-06-2008
Data Script to : Search and replace

Hi Chaps,

I have a file which is like below:

>cat file.dat

FIRSTP SECONDP PATH="c:\ftp\dir\test.dat" USER=user1 PASS=*PASSWORD*
Sub1=Dir
Sub2=Test
>

I need to do the below:

1. Take each line, check if the line contains the word *PASSWORD*
2. If so check the USER (in this case user1) and lookup in another file pass.dat for the password
3. Replace the *PASSWORD* with the actual password (replace the stars as well)
4. The output file should contain the same lines as input file in the same order with just the password updated

Please could you help?

One of the main problems i find is the "c:\ftp" - somehow the \f is taking it as next line and im unable to manipulate that.

Thanks in advance,
D

Last edited by deepakgang; 10-06-2008 at 11:44 AM..
# 2  
Old 10-06-2008

What part of the script is giving you problems?

What have you tried?

Unless you are doing something very wrong (and weird), there is no way that \f can be taken to mean the next line.

If this is homework, at least make an attempt, and post what you have done.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script to replace text file from a lookup file

Hi. I need assistance with the replacing of text into a specific file via a bash script. My bash script, once run, currently provides a menu of computer names to choose.The script copies onto my system various files, depending what computer was selected in the menu.This is working OK. Now, I... (1 Reply)
Discussion started by: jonesn2000
1 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

File field to replace lookup from another file

Hi All, I don't know how to fast do this field replace that need lookup from another file to form the update result:confused: I want to do it by general shell script Can anyone help to solve it ? Thanks for your kindly reply in advance. CK (0 Replies)
Discussion started by: ckwong99
0 Replies

4. Shell Programming and Scripting

Perl value lookup and replace

Hi, I have an input file and a config file which I need to lookup values in using Perl: Input file: ID, Value COMP0,0 COMP1,1 COMP2,2 COMP3,3 COMP4,3 COMP5,5Config file: ID, Operation COMP0,((@COMP1@ + @COMP2@ + @COMP3@) / @COMP4@) + @COMP5@Expected output: ID, Value COMP0,7 # This... (0 Replies)
Discussion started by: Subbeh
0 Replies

5. UNIX for Dummies Questions & Answers

Help with search and replace or search only of / in vi

Hi all, I am editing a config file in vi that has a / on it. At the moment, search and replace looks alright as am able to use a # as a temporary separator, i.e. :,$s#/u01/app#/u02/app#g For doing a search, I have to escape the / do. So if I want to search for /u01/app, I am having to do... (2 Replies)
Discussion started by: newbie_01
2 Replies

6. 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

7. 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

8. Shell Programming and Scripting

Search, replace string in file1 with string from (lookup table) file2?

Hello: I have another question. Please consider the following two sample, tab-delimited files: File_1: Abf1 YKL112w Abf1 YAL054c Abf1 YGL234w Ace2 YKL150w Ace2 YNL328c Cup9 YDR441c Cup9 YDR442w Cup9 YEL040w ... File 2: ... ABF1 YKL112W ACE2 YLR131C (9 Replies)
Discussion started by: gstuart
9 Replies

9. UNIX for Advanced & Expert Users

Clueless about how to lookup and reverse lookup IP addresses under a file!!.pls help

Write a quick shell snippet to find all of the IPV4 IP addresses in any and all of the files under /var/lib/output/*, ignoring whatever else may be in those files. Perform a reverse lookup on each, and format the output neatly, like "IP=192.168.0.1, ... (0 Replies)
Discussion started by: choco4202002
0 Replies

10. 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
Login or Register to Ask a Question