Use of $0, $1, $2, etc In Linux In Hindi

AWK mein $0, $1, $2, aadi variables field access aur manipulation ke liye istemal hote hain. In variables ka istemal input lines ko parse aur process karne ke liye hota hai, sath hi AWK mein if, for, aur while statements ke saath bhi istemal kiya ja sakta hai. Yahan kuch examples diye gaye hain jo in concepts ko demonstrate karte hain:

Use of $0, $1, $2, etc In Linux In Hindi

1. Field Access Using $0, $1, $2, etc.:

AWK mein $0 current line ko represent karta hai, $1 se $NF tak variables line ke fields (words) ko represent karte hain. Iska istemal text data ko parse karne ke liye hota hai.

Example:

# Input line: "John Doe 30"
# Fields: $1="John", $2="Doe", $3="30"
{
    print "Name: " $1
    print "Last Name: " $2
    print "Age: " $3
}

2. if Statement:

if statement ka istemal conditional checks ke liye hota hai. Agar condition true hoti hai, to associated actions execute hote hain.

Example:

{
    if ($3 >= 18) {
        print $1 " is an adult."
    } else {
        print $1 " is a minor."
    }
}

3. for Statement:

for statement ka istemal loops ke liye hota hai. Isse specific range mein actions ko execute kiya ja sakta hai.

Example:

# Print numbers from 1 to 5
{
    for (i = 1; i <= 5; i++) {
        print "Number: " i
    }
}

4. while Statement:

while statement ka istemal ek condition true rahe tak loop execute karne ke liye hota hai.

Example:

# Print numbers from 1 to 5 using a while loop
{
    i = 1
    while (i <= 5) {
        print "Number: " i
        i++
    }
}

AWK mein $0, $1, $2, aadi variables ka istemal input lines ko parse karne mein hota hai, jabki if, for, aur while statements conditional checks aur loops ke liye istemal hote hain. In concepts ka istemal text data processing aur manipulation ke liye kiya jata hai AWK programs mein.

Leave a Comment