Awk program structure In Linux In Hindi

AWK programs ka structure pattern-action pairs se banta hai, jahaan har pattern ke sath ek ya ek se adhik actions associate kiye jaate hain. Niche AWK program ka basic structure diya gaya hai:

Awk program structure In Linux In Hindi

/pattern/ {
    # Action 1
    # Action 2
    # ...
}

/pattern2/ {
    # Action 1
    # Action 2
    # ...
}

# More pattern-action pairs...

Yahan, har pattern ke liye ek block define kiya gaya hai, aur us block ke andar ek ya adhik actions define kiye gaye hain. Jab AWK program input lines ko read karta hai, to woh har line ke liye pattern-action pairs ko evaluate karta hai. Agar koi pattern match hoti hai, to uske sath associated actions execute hote hain.

Components of an AWK Program:

  1. Pattern: Ye ek expression hoti hai jise AWK line ke content ke sath compare karta hai. Agar pattern match hoti hai, to actions execute hote hain. Pattern ek string, regular expression, ya logical condition ho sakti hai.
  2. Actions: Actions block ke andar define kiye gaye hote hain. Jab pattern match hoti hai, to AWK actions ko execute karta hai. Actions mein aap text processing, calculations, aur variables ko manipulate kar sakte hain.

Example of an AWK Program:

Chaliye ek simple AWK program ka example dekhte hain. Is program mein hum input file mein “user” pattern ke sath match hone wali lines ko print karenge:

/user/ {
    print
}

Is AWK program mein:

  • /user/ pattern ke roop mein “user” pattern hai, jo input lines ke content ko search karega.
  • { print } actions block mein print command hai, jo pattern ke sath match hone wali lines ko output karega.

Is AWK program ko input file ke saath use karke, aap “user” pattern ke sath match hone wali lines ko print kar sakte hain.

AWK programs ka structure pattern-action pairs se banta hai, aur iska istemal text processing aur data manipulation ke liye hota hai. Aap patterns aur actions ko customize karke AWK programs ko apne specific requirements ke hisab se design kar sakte hain.

Leave a Comment