Need to Replace the the Staus in last line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to Replace the the Staus in last line
# 1  
Old 01-21-2016
Need to Replace the the Staus in last line

Hi Team,

I have a increamental file like :

Code:
 1033|20160120211644126508|1845828861|IN PROGRESS|
1033|20160120220756541604|1845828861|IN PROGRESS|
1033|20160120221051036757|1845828861|IN PROGRESS|
1033|20160120221208839263|1845828861|IN PROGRESS|
1033|20160120222550394230|1845828861|IN PROGRESS|

Where the second column is the time stamp, I want to create a script or need a command which can compare the second column and find the max value and update the particular line having max value with Status as COMPLETED

Say:

I/p

Code:
 1033|20160120211644126508|1845828861|IN PROGRESS|
1033|20160120220756541604|1845828861|IN PROGRESS|
1033|20160120221051036757|1845828861|IN PROGRESS|
1033|20160120221208839263|1845828861|IN PROGRESS|
1033|20160120222550394230|1845828861|IN PROGRESS|


O/P

Code:
 1033|20160120211644126508|1845828861|IN PROGRESS|
1033|20160120220756541604|1845828861|IN PROGRESS|
1033|20160120221051036757|1845828861|IN PROGRESS|
1033|20160120221208839263|1845828861|IN PROGRESS|
1033|20160120222550394230|1845828861|COMPLETED|

I am using
Code:
sed -i 's/IN PROGRESS/COMPLETED/' <filename>

but not giving proper result, Also I don't want to use VI editor as I as I need to put the script in my ETL tool code.

Please Suggest

Thanks
Devendra

---------- Post updated at 01:55 AM ---------- Previous update was at 12:51 AM ----------


I/P File:
1033|20160120211644126508|1845828861|IN PROGRESS|
1033|20160120220756541604|1845828861|IN PROGRESS|
1033|20160120221051036757|1845828861|IN PROGRESS|
1033|20160120221208839263|1845828861|IN PROGRESS|
1033|20160120222550394230|1845828861|IN PROGRESS|


sed -i 's/IN PROGRESS/COMPLETED/' <filename>

Last edited by Don Cragun; 01-21-2016 at 01:15 AM.. Reason: Add CODE tags.
# 2  
Old 01-21-2016
If it is an incremental file, can we rely on the maximum timestamp value being the last line of the input?

Does every line in you input always contain IN PROGRESS in the next to the last field? Or, is the real problem to find the last line in the input file that contains IN PROGRESS and change that text on that line to COMPLETED?

If you're really trying to find a maximum value in a field when the input is not in increasing or decreasing mathematical order, neither sed nor vi have that ability (unless you want to use the vi command that replaces text with the output of a shell command to sort the file).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace values in script reading line by line using sed

Hi all, Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE. for pa in PA_VALUE blah blah do for pb in PB_VALUE blah blah do I have a text file with two columns of values for PA and PB. 14.5 16.7 7.8 9.5 5.6 3.6 etc etc I would like to read this... (7 Replies)
Discussion started by: crimsonengineer
7 Replies

2. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

3. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

4. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

6. Emergency UNIX and Linux Support

Find a line using a condition and replace a string in that line

Hello, I have a 100 line code. I have given a sample of it below: ABC*654654*1*54.54*21.2*87*1*654654654654 CCC*FS*FS*SFD*DSF GGG*FGH*CGB*FBDFG*FGDG ABC*654654*1*57.84*45.4*88*2*6546546545 CCC*WSF*SG*FGH*GHJ ADA*AF*SFG*DFGH*FGH*FGTH I need to select the line starting with "ABC" its... (3 Replies)
Discussion started by: nithins007
3 Replies

7. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

8. Shell Programming and Scripting

Server Staus offline to online -Shell script

Hi, We put cron entry :whenever server is offline(checks every 5 minutes) it sends status to mailer group. The number of messages (offline)were growing in our mailbox.How to avoid not to send offline messages after the first one through shell script. Thanks in advance. Chowdary (2 Replies)
Discussion started by: chowdary_m
2 Replies

9. UNIX for Advanced & Expert Users

script to Monitor raid staus --Sun Volume manager

We use Sun Volume manager to mirror root disks and other local disks... Is there any script to monitor raid status across all machines send output thru email? Help is appreciated. Thanks. (1 Reply)
Discussion started by: sriny
1 Replies

10. Shell Programming and Scripting

Staus of Executed Scripts

Hi There, I have 3 scripts that have to be run one after the other. All 3 scripts are dependent of the other. Now, If I am about to run the second script, assuming that the first script has already been run, can I get the status of the first script. The problem is that, My second script has... (11 Replies)
Discussion started by: pathanjalireddy
11 Replies
Login or Register to Ask a Question