Unix Filter Commands grep: Find lines in stdin that match a pattern and print them to stdout. sort: Sort the lines in stdin, and print the result to stdout. uniq: Read from stdin and print unique (that are different from the adjacent line) to stdout. cat: Read lines from stdin (and more files), and concatenate them to stdout. more: Read lines from stdin, and provide a paginated view to stdout. cut: Cut specified byte, character or field from each line of stdin and print to stdout. paste: Read lines from stdin (and more files), and paste them together line-by-line to stdout. head: Read the first few lines from stdin (and more files) and print them to stdout. tail: Read the last few lines from stdin (and more files) and print them to stdout. wc: Read from stdin, and print the number of newlines, words, and bytes to stdout. tr: Translate or delete characters read from stdin and print to stdout. Command grep...
Loops in Unix You may use different loops based on the situation. They are: #1) Unix For loop statement Example: This program will add 1+2+3+4+5 and result will be 15 for i in 1 2 3 4 5 do sum=`expr $sum + $i` done echo $sum #2) Unix While loop statement Example: This program will print the value of ‘a’ five times, from 1 to 5. a=1 while [ $a -le 5 ] do echo “value of a=” $a a=`expr $a + 1` done #3) Unix Until loop statement This program will print the value of ‘a’ two times from 1 to 2. a=1 until [ $a -ge 3 ] do echo “value of a=” $a a=`expr $a + 1` done While running these loops, there may be a need to break out of the loop in some condition before completing all the iterations or to restart the loop before completing the remaining statements. This can be achieved with the ‘break’ and ‘continue’ statements. The following program illustrates the ‘break’ operation: num=1 while [ $num -le 5 ] do read var if [ $var -lt 0 ] then ...
While running a command, the user can pass a variable number of parameters in the command line. Within the command script, the passed parameters are accessible using ‘positional parameters’. These range from $0 to $9, where $0 refers to the name of the command itself, and $1 to $9 are the first through to the ninth parameter, depending on how many parameters were actually passed. Example: $ sh hello how to do you do Here $0 would be assigned sh $1 would be assigned hello $2 would be assigned how And so on … We will now look at some additional commands to process these parameters. #1) set Each process is also associated with a priority. This is used to ensure that the OS is able to fairly allocate time to various processing tasks. The ‘nice’ command can be used to reduced the priority of a process and thus be ‘nice’ to the other processes, i.e. $ nice <command> This line will run the specified command at a lower priority – by default, the priority wi...
Comments
Post a Comment