Sponsored Content
Top Forums Shell Programming and Scripting If pattern match in other column, modify column 3. Post 303029757 by RudiC on Thursday 31st of January 2019 03:15:47 PM
Old 01-31-2019
You may pimp up your own approach by adding an address specification. Be aware that it will NOT change the third field if that doesn't contain 165, or change any other field that holds that value.

Code:
sed -r '/([^|]*\|){4}[^|]*1111\|/ s/\|165\|/|server1|/' file
01-31-2019 19:14:05|device|server1|1548962040165|5c5348f9-0804-1111|file_attach|7271|587|smtp|
01-31-2019 19:14:05|device|165|1548962040165|5c5348f9-0804-1234|file_attach|7271|587|smtp|
01-31-2019 19:14:05|device|165|1548962040028|5c5348f9-0804-6789|file_attach|7271|587|smtp|
 01-31-2019 19:14:05|device|server1|1548165040028|5c5348f9-0804-1111|file_attach|7271|587|smtp|

EDIT: If you want to replace field 3 regardless of its contents, try

Code:
sed -r '/([^|]*\|){4}[^|]*1111\|/ s/(([^|]*\|){2})[^|]*\|/\1server1|/' file


P.S.: you might want to adapt the title of your thread.

Last edited by RudiC; 01-31-2019 at 04:21 PM..
These 2 Users Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

2. Shell Programming and Scripting

Awk or Sed, fubd match in column, then edit column.

FILE A: 9780743551526,(Abridged) 9780743551779,(Unabridged) 9780743582469,(Abridged) 9780743582483,(Unabridged) 9780743563468,(Abridged) 9780743563475,(Unabridged) FILE B: c3saCandyland 9780743518321 "CANDYLAND" "MCBAIN, ED" 2001 c3sbCandyland 9780743518321 ... (7 Replies)
Discussion started by: glev2005
7 Replies

3. Shell Programming and Scripting

Adding Column Values Using Pattern Match

Hi All, I have a file with data as below: A,FILE1_MYFILE_20130309_1038,80,25.60 B,FILE1_MYFILE_20130309_1038,24290,18543.38 C,FILE1_dsc_dlk_MYFILE_20130309_1038,3,10.10 A,FILE2_MYFILE_20130310_1039,85,110.10 B,FILE2_MYFILE_20130310_1039,10,12.10... (10 Replies)
Discussion started by: angshuman
10 Replies

4. Shell Programming and Scripting

awk pattern match and count unique in column

Hi all I have a need of searching some pattern in file by month and then count unique records D11 G11 R11 -------> Pattern available in file S11 Jan$1 to $5 column contains some records in which I want to find unique for this purpose I have written script like below awk '/Jan/ ||... (4 Replies)
Discussion started by: nex_asp
4 Replies

5. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. UNIX for Dummies Questions & Answers

Match sum of values in each column with the corresponding column value present in trailer record

Hi All, I have a requirement where I need to find sum of values from column D through O present in a CSV file and check whether the sum of each Individual column matches with the value present for that corresponding column present in the trailer record. For example, let's assume for column D... (9 Replies)
Discussion started by: tpk
9 Replies

7. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

8. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

9. Shell Programming and Scripting

Delete line by pattern match in column

file: 1|12322|tow| 5|23422|pow| 6|23423|cow| 3|34324|how| deletelines: 12322 23423 My command to delete line while read NUM do awk -F"\|" '$2 !~ /`"$NUM"`/' file >file.back mv file.back file done<deletelines (3 Replies)
Discussion started by: Roozo
3 Replies

10. UNIX for Beginners Questions & Answers

If pattern in column 3 matches pattern in column 2 (any row), print value in column 1

Hi all, I have searched and searched, but I have not found a solution that quite fits what I am trying to do. I have a long list of data in three columns. Below is a sample: 1,10,8 2,12,10 3,13,12 4,14,14 5,15,16 6,16,18 Please use code tags What I need to do is as follows: If a... (4 Replies)
Discussion started by: bleedingturnip
4 Replies
POSTFIX-ADD-FILTER(8)					      System Manager's Manual					     POSTFIX-ADD-FILTER(8)

NAME
postfix-add-filter - add filter service to Postfix master.cf SYNOPSIS
postfix-add-filter [smtp service name...] [smtpd port...] DESCRIPTION
The postfix-add-filter(8) command adds an smtp service named smtp service name and and smtpd server listening on smtpd port to etc/post- fix/master.cf to facilitate integration of SMTP filters such as amavisd-new or clamsmtp. The configuration is based on the upstream recom- mendations for amavisd-new 2.6.0. Adminstrators should verify it is appropriate for their requirements. The original file is copied prior to modification and left in /etc/postfix to make it possible to revert changes easily. Available in the Debian package for Postfix version 2.5.3 and later. DIAGNOSTICS
If the given smtp service name or smtpd port already appear in the master.cf, a message will be printed to standard out and master.cf will not be modified. ENVIRONMENT
MAIL_CONFIG Directory with Postfix configuration files. The postfix-add-filter(8) command should use this, but it currently doesn't. It is hard coded to /etc/postfix. This should be changed. CONFIGURATION PARAMETERS
None FILES
/etc/postfix/master.cf SEE ALSO
postconf(5), Postfix configuration LICENSE
This software is licensed under the MIT open source license. AUTHOR(S) Scott Kitterman <scott@kitterman.com> POSTFIX-ADD-FILTER(8)
All times are GMT -4. The time now is 10:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy