Sponsored Content
Top Forums Shell Programming and Scripting Pattern search and modify the values Post 302959450 by Scrutinizer on Monday 2nd of November 2015 11:13:52 PM
Old 11-03-2015
Quote:
Originally Posted by vinus
The field numbers are always equal.

---------- Post updated at 03:12 PM ---------- Previous update was at 03:10 PM ----------



I'm not sure whether this logic will work because ^F509 can come anywhere in the file (not $2) .
Ok, adjusted to any field:
Code:
awk '{for(i=1; i<=NF; i++) if($i~/^F509=/){split($i,F,/=/); if(n=="")n=F[2]; $i=F[1]"="n++}}1' FS=^ OFS=^ file

---
Quote:
Originally Posted by RudiC
Try
Code:
awk 'match ($0, /\^F509[^^]*/) && !L {L=1; m=n=substr ($0, RSTART+6, RLENGTH-6)} {sub (m, n++)}1' /tmp/inputfile.txt
[ .. ]

This will fail if there is a line that happens to have the same sequence of numbers before the F509 field. Then sub (m, n++) will substitute those numbers instead of those in the F509 field...

Last edited by Scrutinizer; 11-03-2015 at 12:19 AM..
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

modify a particular pattern starting from second line of the search pattern

Hi, I am new to this forum and i would like to get help in this issue. I have a file 1.txt as shown: apple banana orange apple grapes banana orange grapes orange .... Now i would like to search for pattern say apple or orange and then put a # at the beginning of the pattern... (2 Replies)
Discussion started by: imas
2 Replies

2. UNIX for Dummies Questions & Answers

modify a particular pattern starting from second line of the search pattern

Hi, I think you ppl did not get my question correctly, let me explain I have 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: ... (1 Reply)
Discussion started by: imas
1 Replies

3. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

4. Shell Programming and Scripting

Help with search and delete/add/modify script

Gurus, I need to run a script on multiple XML files in different directories and do the following (the output can be redirected to create a new file) 1. Search a pattern like "abc.mno.xyz" in an XML file, once detected, the script should delete one line above and 3 lines below (including the... (2 Replies)
Discussion started by: inditopgun
2 Replies

5. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

6. Shell Programming and Scripting

How to use sed to modify a line above or below matching pattern?

I couldn't figure out how to use sed or any other shell to do the following. Can anyone help? Thanks. If seeing a string (e.g., TODAY) in the line, replace a string in the line above (e.g, replace "Raining" with "Sunny") and replace a string in the line below (e.g., replace "Reading" with... (7 Replies)
Discussion started by: sprinner
7 Replies

7. Shell Programming and Scripting

modify a file by inserting a conditional values

Hi, input file CCCC 1204 215764.85 9405410.40 1189 DDDD 4498 1503 4617 1507 4723 1517 4829 1528 4996 1540 DDDD 5199 1556 5278 1567 5529 1603 5674 1614 6076 1915 DDDD 6605 2371 7004 2779 CCCC ... (4 Replies)
Discussion started by: Indra2011
4 Replies

8. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

9. Shell Programming and Scripting

Modify existing values in a file

Hi, I am trying to write a shell script which will modify existing values and take backup of old values. file trying to modify is : /etc/sysctl.conf script name: modify.sh execute ./modify.sh enter ref no: 123 add below values in file sysctl.cnf kernel.shmall = 4194304 ... (7 Replies)
Discussion started by: darling
7 Replies

10. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies
All times are GMT -4. The time now is 01:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy