Sponsored Content
Top Forums Shell Programming and Scripting Need a Linux command for find/replace column based on specific criteria. Post 302995407 by transat on Wednesday 5th of April 2017 01:03:45 PM
Old 04-05-2017
Need a Linux command for find/replace column based on specific criteria.

I'm new to shell programming, I have a huge text file in the following format, where columns are separated by single space:
Code:
ACA MEX 4O_ $98.00 $127.40 $166.60 0:00 0:00 0 ;
ACA YUL TS_ $300.00 $390.00 $510.00 0:00 0:00 0 ;
ACA YYZ TS_ $300.00 $390.00 $510.00 0:00 0:00 0 ;
ADZ YUL TS_ $300.00 $390.00 $510.00 0:00 0:00 0 ;
ADZ YYZ TS_ $300.00 $390.00 $510.00 0:00 0:00 0 ;
AGP AMS HV_ $441.00 $573.30 $749.70 0:00 0:00 0 ;
AGP AMS VY_ $235.00 $305.50 $399.50 0:00 0:00 0 ;

I want to replace all values in the 5th column by $-1.00 only when the third column is equal to "TS_". Basically the result of transforming the following line:
Code:
ACA YUL TS_ $300.00 $390.00 $510.00 0:00 0:00 0 ;

Would be:

Code:
ACA YUL TS_ $300.00 $-1.00 $510.00 0:00 0:00 0 ;

Is there any easy way to do it via AWK command ?

Please advise.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 04-05-2017 at 03:47 PM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Select records based on search criteria on first column

Hi All, I need to select only those records having a non zero record in the first column of a comma delimited file. Suppose my input file is having data like: "0","01/08/2005 07:11:15",1,1,"Created",,"01/08/2005" "0","01/08/2005 07:12:40",1,1,"Created",,"01/08/2005"... (2 Replies)
Discussion started by: shashi_kiran_v
2 Replies

2. Shell Programming and Scripting

Append specific lines to a previous line based on sequential search criteria

I'll try explain this as best I can. Let me know if it is not clear. I have large text files that contain data as such: 143593502 09-08-20 09:02:13 xxxxxxxxxxx xxxxxxxxxxx 09-08-20 09:02:11 N line 1 test line 2 test line 3 test 143593503 09-08-20 09:02:13... (3 Replies)
Discussion started by: jesse
3 Replies

3. Shell Programming and Scripting

substract column based on some criteria

Please guide if you know how to solve this. I have a tab delimited INPUT FILE where each record is separated by ----- ----- ABC 4935402 4936680 Pattern=Cheers07080.1 ABC 4932216 4932368 Pattern=Cheers07080.1 ABC 4931932 4932122 ... (8 Replies)
Discussion started by: sam_2921
8 Replies

4. Shell Programming and Scripting

Need an awk for a global find/replace in a file, specific column

I am new to unix and awk/sed etc... using C-Shell. Basically, I have a fixed length file that has 4 different record types on it, H, D, V, W all in column 1. I need to change all the W's in column 1 to D's. in the entire file. The W's can be anywhere in the file and must remain in the same... (3 Replies)
Discussion started by: jclanc8
3 Replies

5. UNIX for Dummies Questions & Answers

AWK Command to find text in specific column

I'm new to scripting and would appreciate any help. I have a list of over 20 words in File1 that I need to find in columns 10-15 of File2. I need the entire row of File2 that the File1 list matches. I originally used a grep command which works, but provides File1 results that can be found... (3 Replies)
Discussion started by: Chillin
3 Replies

6. Shell Programming and Scripting

Extract data based on specific search criteria

I have a huge file (about 2 millions records) contains data separated by “,” (comma). As part of the requirement, I can't change the format. The objective is to remove some of the records with the following condition. If the 23rd field on each line start with 302 , I need to remove that from the... (4 Replies)
Discussion started by: jaygamini
4 Replies

7. Shell Programming and Scripting

Find and replace string matching criteria

Dear Friends, I am looking for a way to replace a string (multiple lines) starting with something and ending with something (these two values do not change) with blank. Basically I want to delete this code injection accross many sites and folders. Search Code (across files and folders) that... (2 Replies)
Discussion started by: libras
2 Replies

8. Shell Programming and Scripting

Extract error records based on specific criteria from Unix file

Hi, I look for a awk one liner for below issue. input file ABC 1234 abc 12345 ABC 4567 678 XYZ xyz ght 678 ABC 787 yyuu ABC 789 7890 777 zxr hyip hyu mno uii 678 776 ABC ty7 888 All lines should be started with ABC as first field. If a record has another value for 1st... (7 Replies)
Discussion started by: ratheesh2011
7 Replies

9. Shell Programming and Scripting

Help with replace specific column command

Input file: ASD_QAW 12 A_@ AE_AQ 21 PA_123 ASDA_@ 23 ADA_AS . . Output file: ASD_QAW 12 A @ AE_AQ 21 PA 123 ASDA_@ 23 ADA AS . . Do anybody know how to just specific and replace "_" in column 3 with tab delimiter (\t)? Thanks for advice. (2 Replies)
Discussion started by: perl_beginner
2 Replies

10. Shell Programming and Scripting

awk to print specific line in file based on criteria

In the file below I am trying to extract a specific instance of path, if the adjacent plugin": "/rundb/api/v1/plugin/49/. Thank you :). file "path": "/results/analysis/output/Home/Auto_user_S5-00580-4-Medexome_65_028/plugin_out/FileExporter_out.52", "plugin": "/rundb/api/v1/plugin/49/",... (8 Replies)
Discussion started by: cmccabe
8 Replies
Smokeping_probes_EchoPing(3)					     SmokePing					      Smokeping_probes_EchoPing(3)

NAME
Smokeping::probes::EchoPing - an echoping(1) probe for SmokePing OVERVIEW
Measures TCP or UDP echo (port 7) roundtrip times for SmokePing. Can also be used as a base class for other echoping(1) probes. SYNOPSIS
*** Probes *** +EchoPing binary = /usr/bin/echoping forks = 5 offset = 50% step = 300 # The following variables can be overridden in each target section extraopts = -some-letter-the-author-did-not-think-of fill = A ipversion = 4 pings = 5 priority = 6 size = 510 timeout = 1 tos = 0xa0 udp = no waittime = 1 # [...] *** Targets *** probe = EchoPing # if this should be the default probe # [...] + mytarget # probe = EchoPing # if the default probe is something else host = my.host extraopts = -some-letter-the-author-did-not-think-of fill = A ipversion = 4 pings = 5 priority = 6 size = 510 timeout = 1 tos = 0xa0 udp = no waittime = 1 DESCRIPTION
See echoping(1) for details of the options below. VARIABLES
Supported probe-specific variables: binary The location of your echoping binary. Default value: /usr/bin/echoping forks Run this many concurrent processes at maximum Example value: 5 Default value: 5 offset If you run many probes concurrently you may want to prevent them from hitting your network all at the same time. Using the probe- specific offset parameter you can change the point in time when each probe will be run. Offset is specified in % of total interval, or alternatively as 'random', and the offset from the 'General' section is used if nothing is specified here. Note that this does NOT influence the rrds itself, it is just a matter of when data acqusition is initiated. (This variable is only applicable if the variable 'concurrentprobes' is set in the 'General' section.) Example value: 50% step Duration of the base interval that this probe should use, if different from the one specified in the 'Database' section. Note that the step in the RRD files is fixed when they are originally generated, and if you change the step parameter afterwards, you'll have to delete the old RRD files or somehow convert them. (This variable is only applicable if the variable 'concurrentprobes' is set in the 'General' section.) Example value: 300 Supported target-specific variables: extraopts Any extra options specified here will be passed unmodified to echoping(1). Example value: -some-letter-the-author-did-not-think-of fill The "-f" echoping(1) option. Example value: A ipversion The IP protocol used. Possible values are "4" and "6". Passed to echoping(1) as the "-4" or "-6" options. Example value: 4 pings How many pings should be sent to each target, if different from the global value specified in the Database section. Note that the number of pings in the RRD files is fixed when they are originally generated, and if you change this parameter afterwards, you'll have to delete the old RRD files or somehow convert them. Example value: 5 priority The "-p" echoping(1) option. Example value: 6 size The "-s" echoping(1) option. Example value: 510 timeout The "-t" echoping(1) option. Example value: 1 Default value: 5 tos The "-P" echoping(1) option. Example value: 0xa0 udp The "-u" echoping(1) option. Values other than '0' and 'no' enable UDP. Example value: no waittime The "-w" echoping(1) option. Example value: 1 AUTHORS
Niko Tyni <ntyni@iki.fi> BUGS
Should we test the availability of the service at startup? After that it's too late to complain. The location of the echoping binary should probably be a global variable instead of a probe-specific one. As things are, every EchoPing -derived probe has to declare it if the default (/usr/bin/echoping) isn't correct. SEE ALSO
echoping(1), Smokeping::probes::EchoPingHttp etc., <http://echoping.sourceforge.net/> 2.6.8 2013-03-17 Smokeping_probes_EchoPing(3)
All times are GMT -4. The time now is 07:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy