Archive for September, 2007

The value that you assign a variable can (Web hosting reseller)

Sunday, September 30th, 2007

The value that you assign a variable can also be the value of another variable or a field. For example, the following awk commands fruit=peach fruity=fruit set the value of the variables fruit and fruity to peach. In order to set the value of a variable to one of the fields parsed by awk, you need to use the standard field access operator. For example, the following awk command fruit=$1 sets the value of the variable fruit to the first field of the input line. Using Numeric Expressions You can also assign a variable the value of a numeric expression. Numeric expressions are commands used to add, subtract, multiply, and divide two numbers. Numeric expressions are constructed using the numeric operators given in Table 17.2. The numeric expressions are of the form num1 operator num2 Here num1 and num2 can be constants, such as 1 or 2, or variable names. A numeric expression performs the action specified by operator on num1 and num2 and returns the answer. For example, the following awk commands a=1 b=a+1 assign the value 2 to the variable b. Table 17.2 Numeric Operators in awk Operator Description + Add - Subtract * Multiply / Divide % Modulo (Remainder) ^ Exponentiation As an example of using numeric expressions, look at the following script that counts the number of blank lines in a file:
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Sams Teach Yourself Shell Programming in (Ecommerce web host) 24 Hours

Saturday, September 29th, 2007

Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 17: Filtering Text with awk Previous Chapter Next Chapter Sections in this Chapter: What is awk? Questions Using awk Features Terms Summary Previous Section Next Section Using awk Features Variables Flow Control You have seen some of the basics of using awk, and you’ll now look at some of the more powerful features that it provides. The main topics are l Variables l Flow control l Loops These features let you fully exploit the power of awk. Variables Variables in awk are similar to variables in the shell: They are words that refer to a value. The basic syntax of defining a variable is name=value Here name is the name of the variable, and value is the value of that variable. For example, the following awk command fruit=”peach” creates the variable fruit and assigns it the value peach. There is no need to initialize a variable: the first time you use it, it is initialized. Like the shell, the name of a variable can contain only letters, numbers, and underscores. A variable’s name cannot start with a number. You can assign both numeric and string values to a variable in the same script. For example, consider the following awk commands: fruit=”peach” fruit=100 The first command assigns the value peach to the variable fruit. The second command assigns the value 100 to the variable fruit.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

$ ls -l produces output formatted similar to (Net web server)

Friday, September 28th, 2007

$ ls -l produces output formatted similar to the following: total 64 -rw-r–r– 1 ranga users 635 Nov 29 11:10 awkfruit.sh -rw-r–r– 1 ranga users 115 Nov 28 14:07 fruit_prices.txt -rw-r–r– 1 ranga users 80 Nov 27 13:53 fruit_prices.txt.7880 lrwxrwxrwx 1 ranga users 8 Nov 27 19:01 nash -> nash.txt -rw-r–r– 1 ranga users 62 Nov 27 16:06 nash.txt -rw-r–r– 1 ranga users 11 Nov 29 10:38 nums.txt lrwxrwxrwx 1 ranga users 8 Nov 27 19:01 urls -> urls.txt -rw-r–r– 1 ranga users 180 Nov 27 12:34 urls.txt You can use awk to manipulate the output of the ls -l command so that only the name of a file and its size are printed. Here, the name of the file is in field 9, and the size is in field 5. The following command prints the name of each file along with its size: $ /bin/ls -l | awk ‘$1 !~ /total/ { printf “%-32s %sn”,$9,$5 ; }’ The output looks like the following: awkfruit.sh 635 fruit_prices.txt 115 fruit_prices.txt.7880 80 nash 8 nash.txt 62 nums.txt 11 urls 8 urls.txt 180 Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 17: Filtering Text with awk Previous Chapter Next Chapter Sections in this Chapter: What is awk? Questions Using awk Features Terms Summary Previous Section Next Section Copyright Macmillan Computer Publishing. All rights reserved.
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Top ten web hosting - Clearly it is performing more work than it

Thursday, September 27th, 2007

Clearly it is performing more work than it needs to. For example, when the input line is Kiwi $1.50 22 the execution of the script is as follows: 1. Check whether the value of the third column, 22, is less than 75. Because the value is less than 75, the script proceeds to step 2. 2. Prints the input line followed by REORDER. 3. Checks whether the value of the third column, 22, is greater than 75. Because the value is not greater than 75, the script reads the next line. As you can see, you have no real need to execute step 3 because step 2 has already printed a line. To prevent step 3 from executing, you can use the next command. The next command tells awk to skip all the remaining patterns and expressions and instead read the next input line and start from the first pattern or expression. Change your script to use it: #!/bin/sh awk ‘ $3 <= 75 { printf "%st%sn",$0,"REORDER" ; next ; } $3 > 75 { print $0 ; } ‘ fruit_prices.txt ; Now the execution of the script is as follows: 1. Checks whether the value of the third column, 22, is less than 75. Because the value is less than 75, the script proceeds to step 2. 2. Prints the input line followed by REORDER. 3. Reads the next input line and starts over with the first pattern. As you can see, the second comparison ( $3 > 75 ) is never performed for this input line. Using STDIN as Input Recall that the basic form of an awk command is awk ’script’ files If files, the list of files, is omitted, awk reads its input from STDIN. This enables us to use it to filter the output of other commands. For example, the command
We recommend high quality webhost to host and run your jsp application: christian web host services.

Pineapple $1.29 35 (Dedicated web hosting) REORDER Apple $0.99 78 Compound

Wednesday, September 26th, 2007

Pineapple $1.29 35 REORDER Apple $0.99 78 Compound Expressions Often you need to combine two or more expressions to check for a particular condition. When you combine two or more expressions, the result is called a compound expression . Compound expressions are constructed by using either the && (and) or the || (or) compound operators. The syntax is (expr1) && (expr2) (expr2) || (expr2) Here expr1 and expr2 are expressions constructed using the conditional operators given in Table 17.1. The parentheses surrounding expr1 and expr2 are required. When the && operator is used, both expr1 and expr2 must be true for the compound expression to be true. When the || operator is used, the compound expression is true if either expr1 or expr2 is true. As an example of using a compound expression, you can use the compound operators to obtain a list of all the fruit that cost more than a dollar and of which there are less than 75: awk ‘ ($2 ~ /^$[1-9][0-9]*.[0-9][0-9]$/) && ($3 < 75) { printf "%st%st%sn",$0,"*","REORDER" ; } ' fruit_prices.txt ; The output looks like the following Kiwi $1.50 22 * REORDER Pineapple $1.29 35 * REORDER The Compound Expression Operators You might hear the && operator called the and-and operator because it consists of two ampersands ( and characters). Similarly, the || operator might be referred to as the or-or operator. The next Command Consider the following script: #!/bin/sh awk ' $3 <= 75 { printf "%st%sn",$0,"REORDER" ; } $3 > 75 { print $0 ; } ‘ fruit_prices.txt
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Comparison Operators Say that you have to flag

Tuesday, September 25th, 2007

Comparison Operators Say that you have to flag all the fruit whose quantity is less than 75 for reorder by appending the string REORDER to the end of their line. In this case you have to check whether the third field, which holds the quantity, is less than or equal to 75. To solve this problem, you need to use a comparison operator. In awk, comparison operators compare the values of numbers and strings. Their behavior is similar to operators found in the C language or the shell. When you use a comparison operator, the syntax of an awk command changes to the following: expression { actions; } Here expression is constructed using one of the comparison operators given in Table 17.1 Table 17.1 Comparison Operators in awk Operator Description < Less than > Greater than <= Less than or equal to >= Greater than or equal to == Equal to != Not equal to value ~ / pattern/ True if value matches pattern value !~ / pattern/ True if value does not match pattern You can solve your problem using the following script: #!/bin/sh awk ‘ $3 <= 75 { printf "%st%sn",$0,"REORDER" ; } $3 > 75 { print $0 ; } ‘ fruit_prices.txt Here you check to see whether the third field contains a value less than or equal to 75. If it does, you print out the input line followed by the string REORDER. Next you check to see whether the third field contains a value greater than 75 and, if it does, you print the input line unchanged. The output from this scripts looks like the following: Fruit Price/lbs Quantity Banana $0.89 100 Peach $0.79 65 REORDER Kiwi $1.50 22 REORDER
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Kiwi 22 (Free php web host) Pineapple 35 Apple 78 All the

Thursday, September 20th, 2007

Kiwi 22 Pineapple 35 Apple 78 All the features of the printf command discussed in Chapter 13, “Input/Output,” are available in the awk command printf. Taking Pattern-Specific Actions Say that you want to highlight those fruits that cost more than a dollar by putting a * at the end of the line for those fruits. This means that you need to perform different actions depending on the pattern that was matched for the price. Start with the following script: #!/bin/sh awk ‘ / *$[1-9][0-9]*.[0-9][0-9] */ { print $1,$2,$3,”*”; } / *$0.[0-9][0-9] */ { print ; } ‘ fruit_prices.txt Here you have two patterns: The first one looks for fruit priced higher than a dollar, and the second one looks for fruit priced lower than a dollar. When a fruit priced higher than a dollar is encountered, the three fields are output with a * at the end of the line. For all other fruit, the line is printed exactly as it was read. The output looks like the following: Banana $0.89 100 Peach $0.79 65 Kiwi $1.50 22 * Pineapple $1.29 35 * Apple $0.99 78 The main problem here is that the lines you wanted to flag with the * in are no longer formatted in the same manner as the other lines. You could solve this using printf, but a much nicer and simpler solution is to use the $0 field. The variable 0 is used by awk to store the entire input line as it was read. Change the script as follows: #!/bin/sh awk ‘ / *$[1-9][0-9]*.[0-9][0-9] */ { print $0,”*”; } / *$0.[0-9][0-9] */ { print ; } ‘ fruit_prices.txt This changes the output so that all the lines are formatted identically: Banana $0.89 100 Peach $0.79 65 Kiwi $1.50 22 * Pineapple $1.29 35 * Apple $0.99 78
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

One of the nicest features available in awk (Apache web server for windows)

Wednesday, September 19th, 2007

One of the nicest features available in awk is that it automatically divides input lines into fields. A field is a set of characters that are separated by one or more field separator characters. The default field separator characters are tab and space. When a line is read, awk places the fields that it has parsed into the variable 1 for the first field, 2 for the second field, and so on. To access a field, use the field operator, $. Thus, the first field is $1. Caution - The use of the $ in awk is slightly different than in the shell. The $ is required only when accessing the value of a field variable; it is not required when accessing the values of other variables. I will explain creating and using variables in awk in depth later in this chapter. As an example of using fields, you can print only the name of a fruit and its quantity using the following awk command: $ awk ‘{ print $1 $3 ; }’ fruit_prices.txt Here you use awk to print two fields from every input line: l The first field, which contains the fruit name l The third field, which contains the quantity The output looks like the following: FruitQuantity Banana100 Peach65 Kiwi22 Pineapple35 Apple78 Notice that in the output there is no separation between the fields. This is the default behavior of the print command. To print a space between each field you need to use the , operator as follows: $ awk ‘{ print $1 , $3 ; }’ fruit_prices.txt Fruit Quantity Banana 100 Peach 65 Kiwi 22 Pineapple 35 Apple 78 You can format the output by using the awk printf command instead of the print command as follows: $ awk ‘{ printf “%-15s %sn” , $1 , $3 ; }’ fruit_prices.txt Fruit Quantity Banana 100 Peach 65
We recommend high quality webhost to host and run your jsp application: christian web host services.

The original awk has remained almost the same (Make a web site)

Tuesday, September 18th, 2007

The original awk has remained almost the same since its first introduction to UNIX in 1978. Originally it was intended to be a small programming language for filtering text and producing reports. By the mid-1980s, people were using awk for large programs, so in 1985 its authors decided to extend it. This version, called nawk (as in new awk ), was released to the public in 1987 and became a part of SunOS 4.1. x. Its developers intended for nawk to replace awk eventually. This has yet to happen. Most commercial UNIX versions such as HP-UX and Solaris still ship with both awk and nawk. In 1992 the Institute of Electrical and Electronics Engineers (IEEE) standardized awk as part of its Portable Operating Systems Interface standard (POSIX). gawk, the GNU version of awk, is based on this standard. All Linux systems ship with gawk. The examples in this chapter work with any version of awk. Basic Syntax The basic syntax of an awk command is awk ’script’ files Here files is a list of one or more files, and script is one or more commands of the form: /pattern/ { actions } Here pattern is a regular expression, and actions is one or more of the commands that are covered later in this chapter. If pattern is omitted, awk performs the specified actions for each input line. Look at the simplest task in awk, displaying all the input lines from a file. In this case you use a modified version of the file fruit_prices.txt from the previous chapter: $ awk ‘{ print ; }’ fruit_prices.txt Fruit Price/lbs Quantity Banana $0.89 100 Peach $0.79 65 Kiwi $1.50 22 Pineapple $1.29 35 Apple $0.99 78 Here you use the awk command print to print each line of the input. When the print command is given without arguments, it prints the input line exactly as it was read. Notice that there is a semicolon ( ;) after the print command. This semicolon is required to let awk know that the command has concluded. Strictly speaking, some older versions of awk do not require this, but it is good practice to include it anyway. Field Editing
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Web server on xp - Sams Teach Yourself Shell Programming in 24 Hours

Monday, September 17th, 2007

Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 17: Filtering Text with awk Previous Chapter Next Chapter Sections in this Chapter: What is awk? Questions Using awk Features Terms Summary Previous Section Next Section Hour 17 Filtering Text with awk In Chapter 16, “Filtering Text Using Regular Expressions,” you looked at the sed command and used regular expressions to filter text. In this chapter you will look at another powerful text filtering command called awk. The awk command is a complete programming language that enables you to search many files for patterns and conditionally modify files without having to worry about opening files, reading lines, or closing files. It’s found on all UNIX systems and is quite fast, easy to learn, and extremely flexible. This chapter concentrates on the awk elements that are most commonly used in shell scripts. Specifically these features are l Field editing l Variables l Flow control statements What is awk? Basic Syntax Comparison Operators Field Editing Using STDIN as Input Taking Pattern-Specific Actions The awk command is a programming language that enables you to search through files and modify records with these files based on patterns. The name awk comes from the last names of its creators Alfred Aho, Peter Weinberger, and Brian Kernighan. It has been a part of UNIX since 1978, when it was added to UNIX Version 7. Currently three main versions are available: l The original awk l A newer version nawk l The POSIX/GNU version gawk
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.