Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request for help on awk .

Status
Not open for further replies.

kttan84

Vendor
Jan 19, 2016
10
MY
Hi ,
im have few question :

1. i have 1 data file, and want to modify all the file name same as file 1.(if possible ignore capital latter,and ignore file not exits)

file 1:
C123
C143
C122
C2

file c123:
pattern1
other text
pattern2
other text
pattern3(replace this line if pattern1 and pattern2 are meet)


 
I don't think it's clear what you want. Can you restate your goal and give another example?

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
thank you for reply.

example:
i have a text file, call file_1
file_1 content:
file_A
file_B
file_C
file_D


inside my folder have alot of file, but i'm just want modify the content for file that shown at file_1.
if found file name call file_A , then check the content inside , if meet the pattern1, pattern2 and pattern 3 , replace the pattern3 to new text.

example file C123 :
pattern1
other text
pattern2
other text
pattern3(replace this line if pattern1 and pattern2 are meet)

 
I'm sorry, I still don't understand what you need. What have you tried so far?


==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
Your files doesn't contain data structured in columns. First file contains only the names of files and other files seems to contain lines with some unstructured text data. So, I don't see any advantage why it should be done in awk. I would do it in other scripting language. However, if you want to do it in awk, you can, but first make a little effort, try to write something self, post here your code, say us where are you stucked and then ask your questions. Please be clear that this is not a free coding service.
 
Not a sign of the word AWK anywhere I'm afraid but if I have understood the op's question this would do it ...

Code:
 for _FILE in `cat file_1`; do if (fgrep -epattern1 -epattern2 $_FILE) then perl -pi.orig -e 's/pattrn3/ChangedIt/' $_FILE; fi ; done

Assuming the OP was wanting to:

1) Go through a list of files that are listed in file_1
2) for each of those files look for a match of the two strings pattern1 AND pattern2
3) if that matches both strings then if pattern3 is also in that file then rewrite pattern3 to something else in the example above to "ChangedIt"
4) If not either of 3 then just move on
5) Oh and in my case I backup the original file to .orig



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top