Find string from file,search in table based on the string,then replace string with result in newfile
Could anyone please help me to get solution for my below requirement. As i'm beginner to shell scripting, i don't have complete idea to achieve solution for below requirement. i tried "cut" and awk to split the file, then after that how we can search in table and to use that result to replace the string in file.
I'm using ksh.
I'm having abc.dat file with the content as below
I'm having a table DEP_TABLE as below
Here i want to find the record which having EMP_DEP as D5 and need to select the coresponding EMP_des from DEP_TABLE (WHERE condition needs to use EMP_DEP, EMP_ID) and that selected EMP_DES need to replace EMP_DEP IN file
1.find the record for a string in a field
2.search in table with the string
3. Replace the string with the new value found from table
EXPECTED OUTPUT
efg.dat file
Moderator's Comments:
Please use code tags when posting data and code samples!
Last edited by vgersh99; 03-30-2020 at 05:05 PM..
Reason: code tags, please!
Hi
I can give a hint for a start. Field separator in 'awk' can be set for each file individually
for instance:
You need to create an array from the data of the first file
and compare with the data of the second
for instance(array create):
It remains to connect together and compare the data
Do you want to only replace the D5 ?
The following merge script replaces D5 and D6 (all what matches);
With your input files it gives the following output
I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this.
string(Scenario 1)- user::r--,user::ourfrd:r--
String(Scenario 2)- user::r--
File
****
# file: /local/Desktop/myfile
# owner: me
# group:... (6 Replies)
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)
I have a file1 with different with multiple fields and records
File2 has 2 fields.
I want to find and replace strings in file1 based on file2 values (I Want an exact match i.e. for example: when searching for DT:3, Substr of DT:34 should not be matched)
File2:
DT:3 foo_err
DT:34 bar_frr... (8 Replies)
Dear all,
I need your help, I have file like this:
file1:23456
01910964830098775635
34567
01942809546554654323
67589
26546854368698023653
09778
58716868568576876878
08675
86178546154065406546
08573
54165843543054354305
.
.file2:
23456 25
34567 26
67589 27 (2 Replies)
here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb
cat dump.sql
INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Hi All,
I am very new to UNIX and I have tried this for a longtime now and unable to crack it....
There is a file that is continuously updating. I need to search for the string and find the date @ which it updated every day.....
eg:
String is "work started"
The log entry is as below:
... (1 Reply)
Hi
I am looking for a particular string in a file.If the string exists, then I want to replace another string with some other text.Once replaced, search for the same text after that character position in the file. :wall:
E.g: Actual File content:
Hello
Name: Nitin Raj
Welcome to Unix... (4 Replies)
Hi All,
My requisite is to search for the string "0108"(which is the year and has come in the wrong year format) in a particular column say 4th column in a tab delimited file and then replace it with 2008(the correct year format) in the same position where 0108 was found in the same file..The... (27 Replies)