Awk programming in Linux In Hindi

AWK ek powerful text processing tool aur programming language hai, jiska istemal text data ko parse aur manipulate karne ke liye kiya jata hai. Yeh Unix aur Unix-like operating systems par kaam karta hai. Chaliye AWK programming ke basics aur commonly used concepts ke bare mein baat karte hain:

Awk programming in Linux In Hindi

1. AWK Syntax:

AWK programs lines of input text ko read karte hain aur user-defined patterns aur actions ke sath match karte hain. Yeh program ke structure ko define karte hain:

/pattern/ {
    # Actions to perform when pattern matches
}
  • /pattern/ line ke liye ek pattern hota hai jise aap search kar rahe hain.
  • {} ke andar actions define kiye jate hain jo pattern ke sath match hone par execute honge.

2. Variables:

AWK mein kai tarah ke built-in variables aur user-defined variables hote hain, jaise ki $0, $1, NF, NR, FS, OFS, RS, ORS, FILENAME, FNR, aadi.

  • $0: Current line ka pura text.
  • $1, $2, …: Fields (words) of the current line, default field separator ke hisab se.
  • NF: Total number of fields in the current line.
  • NR: Current line number.
  • FS: Field separator (default: space/tab).
  • OFS: Output field separator (used when printing fields).
  • RS: Record separator (default: newline).
  • ORS: Output record separator (used when printing lines).
  • FILENAME: Current file name.
  • FNR: Current line number within the current file.

3. Basic AWK Programs:

  • AWK programs text data ko manipulate karne mein use hote hain. For example, lines ko filter, search, replace, aur calculations perform karne ke liye.
  • Yeh ek simple AWK program hai jo “user” pattern ke sath match hone wali lines ko print karega:
  /user/ {
      print
  }

4. AWK Functions:

  • AWK mein kai built-in functions hote hain, jaise ki length(), substr(), tolower(), toupper(), split(), gsub(), int(), rand(), aadi.
  • In functions ka istemal text manipulation aur calculations ke liye hota hai.

5. Command Line Use:

AWK programs ko command line se bhi run kiya ja sakta hai. For example:

awk '/user/ { print }' filename.txt

6. AWK Scripts:

  • AWK programs ko .awk extension ke files mein likh kar run kiya ja sakta hai.
  • Isse complex data manipulation aur parsing tasks ko automate kiya ja sakta hai.

AWK ek versatile tool hai jise text data processing ke liye use kiya jata hai. Aap iska istemal text search, filtering, parsing, aur calculations ke liye kar sakte hain. AWK ke aur bhi advanced concepts hote hain jo complex tasks ko handle karne mein madadgar hote hain.

Leave a Comment