Sponsored Content
Full Discussion: Replace second match+awk/sed
Top Forums Shell Programming and Scripting Replace second match+awk/sed Post 302876306 by klane on Friday 22nd of November 2013 06:08:51 PM
Old 11-22-2013
Wowza! It works! Thanks so much, I've been scratching my head on this problem for a couple days. I think it might help if you wouldn't mind to explain the formatting line by line and what it is doing. I think the logic in my head from my first attempt at the awk statement got scrambled. I think it would help to hear exactly what it was doing.

Also, if I may add a twist...

How would we add in a condition that if it was the last entry for the station, that the close statement date and time would be 12/31/2500 23:59:59? Is there something easy to add in that would do that? Or should I add in some code after this iteration to change the date and time.

For example, for the text sample I gave then it would look like this:
Code:
----------------------------------------- 
sta WP00
 time 10/23/2013 20:10:17 
sensor trillium_240_2 0 583 
add 
close sensor trillium_240_2 10/28/2013 20:20:28  

sensor trillium_120 0 279 
add 
close sensor trillium_120 10/28/2013 20:20:28 
--------------------------------------------- 
sta WP00
 time 10/28/2013 20:20:28
 sensor trillium_240_2 0 583 
add 
close sensor trillium_240_2 12/31/2500 23:59:59  

sensor trillium_120 0 268 
add 
close sensor trillium_120 12/31/2500 23:59:59 
----------------------------------------------

So in effect, it would do what we have done by swapping the times on any of the previous ones (which your code works great for), but then if it was the last station entry (for each station) it would swap it's time for 12/31/2500 23:59:59...make sense?

Last edited by Scrutinizer; 11-23-2013 at 03:41 AM.. Reason: formatting is incorrect on text file data; added code tags (mod)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed scripting, match text within line and replace

New to sed... Have a file foo.txt (below). Need to replace text on 2 lines, but can only feed sed the first few characters of each line (all lines are unique). So, in my example, I have put '$' in place of what I need to figure out how to feed the whole line. What I have thus far: sed -e... (6 Replies)
Discussion started by: boolean2222
6 Replies

2. Shell Programming and Scripting

SED to replace exact match, not first occurrence.

Lets say I have file.txt: (Product:Price:QuantityAvailable) (: as delimiter) Chocolate:5:5 Banana:33:3 I am doing a edit/update function. I want to change the Quantity Available, so I tried using the SED command to replace 5, but my Price which is also 5 is changed instead. (for the Banana... (13 Replies)
Discussion started by: andylbh
13 Replies

3. Shell Programming and Scripting

Match and replace value in 2 different places using awk

Hi, I need help on replacing values in certain field in my file1.txt based on matched patterns in file2.txt using awk. The blue color need to match with one of the data in field $2 in file2.txt. If match, BEGIN and FINISHED value in red will have a new value from field $3 and $4 accordingly.... (3 Replies)
Discussion started by: redse171
3 Replies

4. Shell Programming and Scripting

Match a Pattern & Replace The value Using AWK

I have a csv file in which i have to search a particular string and replace the data in any column with something else. How do i do it using awk. file ------ 2001,John,USA,MN,20101001,29091.50,M,Active,Y 2002,Mike,USA,NY,20090130,342.00,M,Pending,N... (3 Replies)
Discussion started by: Sheel
3 Replies

5. UNIX for Dummies Questions & Answers

awk/sed match and extraction

Hi, I have a file like this- aa 12 23 34 aa 21 34 56 aa 78 45 56 I want to print out only the lines after the last aa. How do I do this? I tried using grep -A and sed -n, but both didnt work as I wanted to. Could someone help me out please.. (3 Replies)
Discussion started by: jamie_123
3 Replies

6. Shell Programming and Scripting

sed Character match and replace

Hello All I am struck in the issue which I want to share with all of you. What I am trying to do is For every line in a file I have to replace a particular character from the given character in a file For Example Suppose the data is 1111x2222 1111x2222 2222y3333 1111x2222 I... (4 Replies)
Discussion started by: adisky123
4 Replies

7. Shell Programming and Scripting

awk Match First Field and Replace Second Column

Hi Friends, I have looked around the forums and over online but couldn't figure out how to deal with this problem input.txt gene1,axis1/0/1,axis2/0/1 gene1,axis1/1/2,axis2/1/2 gene1,axis1/2/3,axis2/2/3 gene2,axis1/3/4,axis2/3/4 Match on first column and if first column is... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

8. Shell Programming and Scripting

Need help with sed to match and replace a string

friends I am struck in a situation where I need to comment a line start with space as below in a file root@LOCALHOST * rw LOCALHOST* r I should comment second line only Any help please (16 Replies)
Discussion started by: mallak
16 Replies

9. Shell Programming and Scripting

sed : replace Nth match in a file

I have a situation where a file "config.txt" looks like this Servername: OS: Serername: OS: Servername: OS: .... .... ... Servername: OS: looking for the sed syntax to replace the "Nth" occurrence of Servername (i would apply the same logic to OS as well), want to replace the Nth... (4 Replies)
Discussion started by: alldbest
4 Replies

10. Shell Programming and Scripting

Pattern match and replace indirect directory reference using sed

Hi, I need a ksh script to replace indirect directory references in an .ini file with a env variable using sed or awk. The .ini file is for example as such: A=.. B=../ C=../.. D=../../ E=../bin F=../../bin G=../../bin/xml H=../../bin/xml/ Need to replace an instance of .. or... (2 Replies)
Discussion started by: andyatit
2 Replies
EGD_SENSOR_TYPE(3)					       EEGDEV library manual						EGD_SENSOR_TYPE(3)

NAME
egd_sensor_type, egd_sensor_name - Get the id or name of a sensor type SYNOPSIS
#include <eegdev.h> int egd_sensor_type(const char* sname); const char* egd_sensor_name(int stype); DESCRIPTION
egd_sensor_type() returns the identifier code of the sensor type named sname. egd_sensor_name() is the reverse process: it retrieves the name of the sensor type identified by stype. Depending on which acquisition devices have been accessed by the library, the sensor type identifier for a given name may be different from a previous program execution. However once a association has been established it is ensured that it will remain the same until the process termination. Additionally, the sensor types named "eeg", "trigger" and "undefined" are always associated respectively to 0, 1 and 2. RETURN VALUE
In case of success, egd_sensor_type() returns a non negative value corresponding to the identifier of the sensor type called name. Other- wise it returns -1. In case of success, egd_sensor_name() returns the name of the sensor type identified by stype. Otherwise, NULL is returned and errno is set accordingly. ERRORS
egd_sensor_type() or egd_sensor_name() will fail if: EINVAL sname is NULL or refers to an unknown sensor type or if stype is not a known sensor type identifier. SEE ALSO
egd_get_numch(3) egd_get_cap(3) EPFL
2011 EGD_SENSOR_TYPE(3)
All times are GMT -4. The time now is 10:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy