I've been reading this forum whenever I had a problem with AWK but I can't seem to find how to solve my problem.
What I would like to do is the following:
I have a first file with two columns, on the first one is a certain name and in the second one, another corresponding name.
In my second file, I would like to search for a certain pattern, and if that pattern is found, search $3 of this line in the second row of file1 and replace it with the corresponding $1 of file 1.
I can always do fairly well with awk on one file, but I don't know how to use two files, I'm a bit lost with the NR==FNR thingy, so your help would be very much appreciated.
Here is what file1 look like:
And here is what file2 looks like:
So, to sum things up I would like my return file to be like:
Thanks a lot for your help.
Teroc
Last edited by Franklin52; 10-29-2009 at 09:07 AM..
Reason: Please use code tags!
Thank you it did the trick, I think I understand how that works now. Thanks for the lesson
One last thing, when I run this script, the file1 is written in the ouput before the corrected file2. Why? NR==FNR {a[$2]=$1} isn't supposed to output anything, is it?
I have this fileA
TEST FILE ABC
this file contains ABC;
TEST FILE DGHT this file contains DGHT;
TEST FILE 123
this file contains ABC,
this file contains DEF,
this file contains XYZ,
this file contains KLM
;
I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
#!/usr/bin/ksh
a="Run successfully"
cd $APPS
ls -l *.txt | while read $txt
do
if then
cp $APPS/$txt cp $hist/$txt
else
rm $APPS/$txt
echo "Files has been removed"
fi
done
New in shell script please help me out
Around 100 txt files in $APPS dir i want to search pattern from... (8 Replies)
Hi Friends,
I am in search of unix command which can search a particular pattern in all files which are created/modified today ONLY. Which is the best way to achieve this?
Thanks in advance. (1 Reply)
I am trying to perform the following action.
1. A script runs the 'last' command for some users and prints the output to a file.
$ cat last_users.log
oracle pts/17 10.120.xxx.xxx Jun 28 14:42 - 18:01 (03:19)
oracle pts/11 10.120.xxx.xxx Jun 28 14:28 - 20:17... (2 Replies)
Hi
I have file1 as
IJU_NSOMOW;
SOWWOD_TWUIQ;
and file2 as
how are you?;
fine there;
Now my problem is i need the output file as
IJU_NSOMOW; how are you?;
SOWWOD_TWUIQ; fine there; (2 Replies)
Hi.
I have 2 files of below format.
File1
AA~1~STEVE~3.1~4.1~5.1
AA~2~DANIEL~3.2~4.2~5.2
BB~3~STEVE~3.3~4.3~5.3
BB~4~TIM~3.4~4.4~5.4
File 2
AA~STEVE~AA STEVE WORKS at AUTO COMPANY
AA~DANIEL~AA DANIEL IS A ELECTRICIAN
BB~STEVE~BB STEVE IS A COOK
I want to match 1st and 3rd... (2 Replies)
how can i merge to files containing some random sort of numbers to a separate file ..
file1
11111
10111
11011
file2
00000
01010
10101
file 3
11111_00000
10111_01010
11011_10101
Please let me know how to do this? (1 Reply)
Hi
I need a command to search files in a directory which does not match with pattern .. Plz send me this
Ex : Test is directory and has some 10 files with different name all are with *.dat extension , need to search files which doesnot contain word "Dummy file".
Thanks (6 Replies)
Afternoon guys,
I have 2 files, 1.txt and 2.txt containing employee numbers.
the 1st file (1.txt) is an extract from sybase with active employee numbers, the 2nd (2.txt) is a scan from the sybase log containing successfull logins *** which i have already mined and now contains only employee... (5 Replies)
Hi there,
I am looking for a shell script which recursively searches all the files under all the directories for a pattern specified in the script. For e.g., i am looking forward to search for the file names which contains numbers of the form 001*****.
Thanks in advance,
Naik (4 Replies)