Sponsored Content
Top Forums Shell Programming and Scripting Add comment on last line if found match Post 303008697 by Don Cragun on Tuesday 5th of December 2017 02:59:55 AM
Old 12-05-2017
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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add a comment line in a text file

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)
Discussion started by: orakhan
2 Replies

2. Shell Programming and Scripting

if match found go to a particular line in perl

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)
Discussion started by: user_prady
17 Replies

3. Shell Programming and Scripting

Need one-liner to look for a line and add it if not found

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)
Discussion started by: brendaT
3 Replies

4. Shell Programming and Scripting

help with script to send email and if subject line match is found

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)
Discussion started by: axdelg
2 Replies

5. Shell Programming and Scripting

add line and remove comment in some script

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)
Discussion started by: debu000
6 Replies

6. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

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)
Discussion started by: eurouno
4 Replies

7. UNIX for Dummies Questions & Answers

Display n lines after match found and other line

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)
Discussion started by: nsuresh316
2 Replies

8. Shell Programming and Scripting

Displaying text till pattern match found in a line

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)
Discussion started by: Optimus81
4 Replies

9. Shell Programming and Scripting

How to print the entire line if the mentioned match is found?

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)
Discussion started by: rahul2662
8 Replies

10. UNIX for Beginners Questions & Answers

Modify text file if found multiple pattern match for every line.

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)
Discussion started by: kttan
16 Replies
FREAD(3)								 1								  FREAD(3)

fread - Binary-safe file read

SYNOPSIS
string fread (resource $handle, int $length) DESCRIPTION
fread(3) reads up to $length bytes from the file pointer referenced by $handle. Reading stops as soon as one of the following conditions is met: o$length bytes have been read o EOF (end of file) is reached o a packet becomes available or the socket timeout occurs (for network streams) o if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually 8192) is made; depending on the previously buffered data, the size of the returned data may be larger than the chunk size. PARAMETERS
o $handle -A file system pointer resource that is typically created using fopen(3). o $length - Up to $length number of bytes read. RETURN VALUES
Returns the read string or FALSE on failure. EXAMPLES
Example #1 A simple fread(3) example <?php // get contents of a file into a string $filename = "/usr/local/something.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); ?> Example #2 Binary fread(3) example Warning On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen(3) mode parameter. <?php $filename = "c:\files\somepic.gif"; $handle = fopen($filename, "rb"); $contents = fread($handle, filesize($filename)); fclose($handle); ?> Example #3 Remote fread(3) examples Warning When reading from anything that is not a regular local file, such as streams returned when reading remote files or from popen(3) and fsockopen(3), reading will stop after a packet is available. This means that you should collect the data together in chunks as shown in the examples below. <?php // For PHP 5 and up $handle = fopen("http://www.example.com/", "rb"); $contents = stream_get_contents($handle); fclose($handle); ?> <?php $handle = fopen("http://www.example.com/", "rb"); if (FALSE === $handle) { exit("Failed to open stream to URL"); } $contents = ''; while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); ?> NOTES
Note If you just want to get the contents of a file into a string, use file_get_contents(3) as it has much better performance than the code above. Note Note that fread(3) reads from the current position of the file pointer. Use ftell(3) to find the current position of the pointer and rewind(3) to rewind the pointer position. SEE ALSO
fwrite(3), fopen(3), fsockopen(3), popen(3), fgets(3), fgetss(3), fscanf(3), file(3), fpassthru(3), ftell(3), rewind(3). PHP Documentation Group FREAD(3)
All times are GMT -4. The time now is 02:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy