×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Request for help on awk .

Request for help on awk .

Request for help on awk .

(OP)
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)


RE: Request for help on awk .

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


RE: Request for help on awk .

(OP)
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)

RE: Request for help on awk .

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


RE: Request for help on awk .

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.

RE: Request for help on awk .

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



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close