Having two input files and hoping to get a third output file with no explanation of the logic to be used to make those changes is not at all likely to get you what you want.
Please tell us what operating system you're using.
Please tell us what shell you're using.
Please clearly explain exactly what text should be added to file 2 when certain conditions are met.
Please clearly explain exactly what conditions need to occur to cause a change to be made to file 2.
Note that putting <space>, <tab>, or (especially) <newline> characters in a filename makes it less likely that people writing scripts to use your file will actually handle your file correctly.
text need at at file 2 if meet the condition is > <space><space>!<space>comment<space>comment at the end of the line.
condition:
if found at file 1 if the line have match at file 2 then add comment.
exp:
file 1: have c12 , then search at file 2 , if found test "analog/c12" then modify this line at file 2, and so on.
Making quite some assumtions as window's awk's version's capabilities are not known (to me), nor is the pattern to search (is "analog/" compulsory?), nor WHAT to add (post#1 and #2 info don't match), nor does the thread title match its contents, would this come close to what you want?
As you can see, a correct and detailed specification helps avoid ambiguities and keeps people from guessing. Be way more precise and specific in the future!
I agree with RudiC that your specification doesn't match the thread title and doesn't match the output you specified in post #1 in this thread. And you haven't said, since you're working on Windows, whether the input files you're using are UNIX text files or DOS text files. The following should work no matter which type of text file you have and produce the same type of output in file 2 that it found in the the original file 2. But, of course, it is making lots of assumptions based on your conflicting requirements. (Note that I still think it is a horrible idea to use filenames containing <space> characters. but this script uses the filenames you specified in post #1.
Note that when you store the above script in a file in Windows, you absolutely must make the text in this file be in UNIX text file format with no <carriage-return> characters in the file. If the location of the Korn shell on Windows is not /bin/ksh, you'll need to change the end of the first line of the script to an absolute path to its location on your systems.
I agree with RudiC that your specification doesn't match the thread title and doesn't match the output you specified in post #1 in this thread. And you haven't said, since you're working on Windows, whether the input files you're using are UNIX text files or DOS text files. The following should work no matter which type of text file you have and produce the same type of output in file 2 that it found in the the original file 2. But, of course, it is making lots of assumptions based on your conflicting requirements. (Note that I still think it is a horrible idea to use filenames containing <space> characters. but this script uses the filenames you specified in post #1.
Note that when you store the above script in a file in Windows, you absolutely must make the text in this file be in UNIX text file format with no <carriage-return> characters in the file. If the location of the Korn shell on Windows is not /bin/ksh, you'll need to change the end of the first line of the script to an absolute path to its location on your systems.
Thank you for reply , it work.
Sorry for not clear explanation given.
i'm a test engineer , sorry not very clear about unix script, i'm looking for for help due to my system running at window with kornshell base.
i have try it , few way search website before post.
1.
i'm looking on how it work on 2 file.
may i know more clear on this :
}' "file 1" "file 2"
2.
may i know is that awk are reading from top to bottom file ?
if this 2 awk, is that it finish the 1st 1 before go to second ?
awk '
{
content
}
awk '
{
content
}
most of the example given are just 1 file on internet.
You can find lots of examples in the UNIX & Linux Forums of awk scripts that work on two or more input files and that produce two or more output files (although we don't need to do the latter in this case).
In an awk program, each group of statements is of the general form:
Before any lines are read from any of the input files named as operands, the commands specified in the actions of all groups with the conditionBEGIN (if there are any) are executed in the order in which they appear in the awk program. There aren't any BEGIN sections in my code for this thread.
After all files of the input files named as operands have been processed, all commands specified in the actions of all groups with the conditionEND (if there are any) are executed in the order in which they appear in the awk program.
All other groups are processed in the order in which they appear in the awk program for every record (with default options, each input line in each file is a record) is processed. If the condition for a group evaluates to a non-zero numeric value or to a non-empty string string value (i.e., evaluates to TRUE), the statements in the action for that group are executed in order; otherwise the statements in that group are skipped for that input record. If there is no condition at the start of a group, the commands in the action in that group are always executed. If the condition evaluates to TRUE and the action and braces ({ and }) are omitted, a default action of print (which prints the current state of the current input record) is performed.
I will assume that you can read the manual page on for awk (by giving the command man awk at a ksh primary prompt in your shell window) to see what the standard awk variables, functions, and statements do. I would hope that the comments I supplied in each group explain what that group is trying to do.
The first group:
(with no condition is executed for every record read from both input files and does exactly what the comments say it does.
The second group:
is executed when the conditionFNR == NR evaluates to TRUE. It evaluates to TRUE when the Number of Records read from the current File (FNR) is equal to the Number of Records read from all files (NR) which happens when any line from the 1st input file is being processed. The next statement in this action causes all remaining statements in the current action (if there are any) and in any following groups to be skipped for this input record, causes the next available input record to be read, and starts processing groups in order for that new input record. The combination of the action and the next statement guarantee that the following group will not be performed for records read from the 1st input file.
The third group:
even though there is no condition is only executed for input files after the 1st input file (and in this code there are only two input files). This group copies the input records as they are read into an output buffer array (o[]) with the index in the array being the current input file record number after searching for and updating any lines that contain the key strings created from lines found in the 1st input file.
The fourth group:
with the actionEND (as described before) evaluates to FALSE for every line read from the two input files and is only processed after end-of-file is reached on both input files. As noted in the comments, this group copies the accumulated output buffer back into the last input file. The number of lines found in the last input file (FNR) and the pathname of the last input file (FILENAME) remain valid during any ENDactions.
Looking for help,
i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it.
have 2 thing need do.
1st
is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018
2nd
is adding... (16 Replies)
Hello Everyone,
I have a file with 5 fields in each line just like mentioned below. Also the 4th field is time elapsed(hh:mm:ss) since the process is running
xyz abc status 23:00:00 idle
abc def status 24:00:00 idle
def gji status 27:00:02 idle
fgh gty status 00:00:00 idle
Here I... (8 Replies)
Hi All,
From the below line if we want to display all the text till found pattern dot/. I was trying with the below code but couldn't able
to print text before the pattern. it display texts which is found after pattern.
awk '/assed/{print;getline;print}' file_name | sed 's/^*. *//'
input... (4 Replies)
I have a file like this
DoctorName
Address1
Address2
DOB
InsuredName
Address1
Address2
DOB
PatientName
Address1
Address2
DOB
ClaimNo1
DoctorName
Address1
Address2
DOB
InsuredName (2 Replies)
Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file.
For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt
I tried with grep -A but it's not supported on my system.
I tried with awk,... (4 Replies)
Hi,
i need some help. i am not sure about my idea.
I have a script directory under my home directory,which has a lot of scripts in it.
These are some names of the scripts in /axxhome/prdv/script
aly300.sh
axt300.sh
arv300.sh
clp300.sh
ctth300.sh
aly400.sh
axt400.sh
arv400.sh... (6 Replies)
Help with script that will check log, then find a match is found, add that as the subject line.
1. The script will always run as a deamon.. and scan the event.log file
2. when a new 101 line is added to the event.log file, have the script check position 5,6 and 7 which is the job name, which... (2 Replies)
I need a good one-liner to look in a specific text file for a line of text and if it's not found, add it at the bottom of the file.
Perl, sed, not particular, whatever works. To make matters worse, the line of text is in a config script with lots of special characters and needs lots of... (3 Replies)
Hello Experts,
I am newbie to perl, just curious to know how to do the following in perl.
suppose I ve a txt file like below. when it founds "*Main Start"
Then go to "*Main End,,,,,,,," patteren and just collect the number from the previous line of "*Main End,,,,,,," pattern . In my... (17 Replies)
Hi I need to add a comment line at the begining of a text file. The scenario is given below.
1. The number of servers that needs to be updated is around 80
2. The location of the text file in all the servers are the same including the file name.
3. The comment has to be added at the very... (2 Replies)