awk to update file with partial matching line in another file and append text
In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in f1, the value in $1 is appended to it at the end of the line with a /test/id/$1_raw.file_fixed.txt. Most of this is static text, except the value from $1 is after the third /. Thank you .
I made an typo in f2
Should just be one column of multiple strings.
So I thought i adjusted the script below correctly to capture the partial match. That is the $2 will be in that long string. Thank you .
Awk
Last edited by cmccabe; 04-17-2019 at 01:23 PM..
Reason: fixed format, updated awk
I made an typo in f2
Should just be one column of multiple strings.
So I thought i adjusted the script below correctly to capture the partial match. That is the $2 will be in that long string. Thank you .
Awk
It still isn't clear to me what you are trying to do, but I assume that the above code is giving errors for trying to divide by an element of an unnamed array and then trying to divide the result of that by a non-numeric string. But, that problem may be hidden by the fact that no value in $2 in f1 (i.e., 0000-yyyy, 1111-xxxx, or the empty string from the 3rd line in f1) ever appears as a field in f2. And, therefore, the condition $2 in id is never true.
And, since there is only one field in every line in f2, the only array subscripts in the id[] array are complete lines from f2. Why run a loop from 1 through NF when NF is always 1?
Since you say that the corrected f2 only contains one string, the first part of the code in both awk scripts above:
could more simply be written as:
or as:
which would both produce exactly the same id[] arrays.
Since there are no matching lines, I still can't make any sense of the description of what you are trying to combine from matching lines in the two files???
These 2 Users Gave Thanks to Don Cragun For This Post:
In the awk below I am trying to add a penalty to a score to each matching $1 in file2 based on the sum of $3+$4 (variable TL) from file1. Then the $4 value in file1 is divided by TL and multiplied by 100 (this valvue is variable S). Finally, $2 in file2 - S gives the updated $2 result in file2.... (2 Replies)
I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output.
$1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Hi,
Anyone can help on how to append a file1.txt into file2.txt after line 3 using sed command.
file1.txt
1. testa
2. testb
3. testc
4. testd
5. test5
6. test6
file2.txt
break here
this is a test
break end here
output
1. testa
2. testb (1 Reply)
Hi,
I had generated a report in my tool as followsoutput.txt
43.35
9
i needed the script to generate a new file like below
i want to append the text to each of these lines of my filenewoutputfile.txt should be
Total Amount : 43.35
Record Count:9
Regards,
Vasa Saikumar.
... (2 Replies)
I have a text file like this:
subject1:LecturerA:10
subject2:LecturerA:40
if I was given string in column 1 and 2 (which are subject 1 and LecturerA) , i need to update 3rd field of that line containing that given string , which is, number 10 need to be updated to 100 ,for example.
The... (6 Replies)
I would like to add a line to the end of a single column text file. How do I go about doing that?
Input:
BEGIN
1
2
3
Output:
BEGIN
1
2
3
END
Thanks! (1 Reply)
Hello, this is probably a simple request but I've been toying with it for a while.
I have a large list of devices and commands that were run with a script, now I have lines such as:
a-router-hostname-C#show ver
I want to print everything up to (and excluding) the # and everything after it... (3 Replies)
Say I have a text file like:
1
3
4
How would I use ksh to put the number '2' into the second line of that file? I'm using OpenBSD so the sed syntax might be a bit different (I have no idea how to use sed, though) (4 Replies)
Hi
I need to append some text @ end of the first line in a file.
like
myfile.txt
list = a,b,c
list.a=some..
I give the arg "d" . now it append at end of first line
list=a,b,c,d
list.a=some...
Please help me out this (7 Replies)