Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Serach pattern in one field and replace in another Post 302677531 by newboy on Thursday 26th of July 2012 12:09:34 PM
Old 07-26-2012
Thanks for soln. I figured out one way to d it myself:

awk -F "\t" -v drv=$mod_pat '$3 ~ drv { OFS= "\t"; $6 = " happy_home"; print;}' sample

---------- Post updated at 06:34 PM ---------- Previous update was at 06:19 PM ----------

I got caught in the else part of condition:

Below I am checking if field 3 matches the pattern specified by drv do whatever next in braces {}

awk -F "\t" -v drv=$mod_pat '$3 ~ drv { OFS= "\t"; $6 = " happy_home"; print;}' sample


The problem now is I want to just print the line untouched if the pattern is not matched. Is this possible in the same command ?
I tried:

awk -F "\t" -v drv=$mod_pat ' if ($3 ~ drv) { OFS= "\t"; $6 = " happy_home"; print;} else {print;}' sample.rpt


But its throwing parse error. Probably some problem with awk syntax.


Any help will be appreciated.

Thanks

---------- Post updated at 09:00 PM ---------- Previous update was at 06:34 PM ----------

Anyhelp ? is this thread closed ?? Smilie

---------- Post updated at 09:39 PM ---------- Previous update was at 09:00 PM ----------

Thanx anyways, got it:

This works:

awk -F "\t" -v drv=$mod_pat '{ if ($3 ~ drv) { OFS= "\t"; $6 = " happy_home"; print;} else {print;} }' sample.rpt

Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find pattern and replace another field

HI all I have a problem, I need to replace a field in a file, but only in the lines that have some pattern, example: 100099C01101C00000000059394200701CREoperadora_TX 100099C01201C00000000000099786137OPERADORA_TX2 in the example above I need to change the first field from 1 to 2 only if... (3 Replies)
Discussion started by: sergiioo
3 Replies

2. Shell Programming and Scripting

serach and replace a specific pattern or value in a xml file

can some one help me with a perl command i have to search and replace a version from a xml-file so i use in a ksh script a command like this ssh $GLB_ACC@$GLB_HOST "/usr/contrib/bin/perl -pi -e "s/$curVersion/$new_Version/g" $Dest_dir/epi.xml" this command worked so far, but the problem... (1 Reply)
Discussion started by: kiranreddy1215
1 Replies

3. UNIX for Dummies Questions & Answers

Pattern Matching - serach and replace script

My requirement is to replace a a particular pattren in a script from A to B. I am not sure if this can be done through sed command or through awk . The file sv.inc is window DialogBox AddConnection tag "~ActiveApp/Add Connection - Provider Type?URL" I would wnat the file to be... (10 Replies)
Discussion started by: bsandeep_80
10 Replies

4. Shell Programming and Scripting

pattern serach using grep

Frds I have to search for a string which is starting with brighton which will be first in the line of a text file test1.txt. The contents of test1.txt are file names like ----- brighton brighton_gt hst_brighton gst_brighton -------so many files------ --------- i have retrieve only... (3 Replies)
Discussion started by: KiranKumarKarre
3 Replies

5. UNIX for Dummies Questions & Answers

Serach a pattern

Hi, I am trying to find a particular patter in multiple UNIX files (also contain system files,hidden files and normal files) i am now using CMD: egrep -ali 'pattern' * i am not getting the required result, i just need files path and finename Naveen (3 Replies)
Discussion started by: Naveen_5960
3 Replies

6. Shell Programming and Scripting

Replace a data in a field if that does not contain a particular pattern

Hi, I have a date/time field in my file. I have to search in all the records and append a timestamp to it, if the timestamp is missing in that field. Is there a possible awk solution for this? Field date format File1 ==== 1|vamu|payer|2007-12-02 02:01:30|bcbs|... (5 Replies)
Discussion started by: machomaddy
5 Replies

7. UNIX for Dummies Questions & Answers

Match pattern in a field, print pattern only instead of the entire field

Hi ! I have a tab-delimited file, file.tab: Column1 Column2 Column3 aaaaaaaaaa bbtomatoesbbbbbb cccccccccc ddddddddd eeeeappleseeeeeeeee ffffffffffffff ggggggggg hhhhhhtomatoeshhh iiiiiiiiiiiiiiii ... (18 Replies)
Discussion started by: lucasvs
18 Replies

8. Shell Programming and Scripting

Script to Serach pattern and give number of occurrences

Hi, I want a script which search for a pattern "good" in a huge file and provide me number of occurences of such pattern in a file. lets say i have a file test.txt contents as below good is good but good is sometime bad and sometime good you are very good and good is always good ... (7 Replies)
Discussion started by: sv0081493
7 Replies

9. Shell Programming and Scripting

Replace pattern from nth field from a file

$ cat /cygdrive/d/Final2.txt 1,A ,Completed, 07.03_23.01 ,Jun 30 20:00 2,BBB,Pending,, 3,CCCCC,Pending,, 4,DDDDD,Pending,, 5,E,Pending,, 6,FFFF,Pending,, 7,G,Pending,, In the above file 4th field is date which is in MM.DD_HH.MIN format and I need to convert it to as it is there in 5th... (1 Reply)
Discussion started by: Amit Joshi
1 Replies

10. Shell Programming and Scripting

Replace pattern from nth field from a file

I have posted this again as old post is closed and I am not able to reopen. so please consider this new post Input File : 1,A,Completed,06.02_19.36,Jun 30 20:00 2,BBB,Failed,07.04_05.12,Jul 21 19:06 3,CCCCC,New,07.21_03.03,Jul 26 12:57 4,DDDDD,Pending,, I wast output file as: ... (7 Replies)
Discussion started by: Amit Joshi
7 Replies
drv(1)                                                              Apple Inc.                                                              drv(1)

NAME
drv - cups driver interface for ppd compiler files SYNOPSIS
drv list drv cat drv:///filename.drv/pcfilename DESCRIPTION
drv lists and compiles PPDC source files installed in the /usr/share/cups/drv and (on Mac OS X) /Library/Printers/PPDs/Contents/Resources directories on behalf of the scheduler, cupsd(8). The first form of the command lists all of the PPD files that can be produced by the driver information files in the two directories. The second form of the command compiles the requested PPD and sends it to the standard output. SEE ALSO
ppdc(1), ppdhtml(1), ppdi(1), ppdmerge(1), ppdpo(1), ppdcfile(5) http://localhost:631/help COPYRIGHT
Copyright 2008-2009 by Apple Inc. 9 March 2009 CUPS drv(1)
All times are GMT -4. The time now is 10:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy