awk programming


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk programming
# 1  
Old 06-19-2002
Question awk programming

Hi folks,

I would like to know the difference between shell programming and awk programming. Actually i have developed a few applications in both but i could not find a better difference other than the syntax differences.

For example, the awk programming syntax is complicated. It has "{" and "}" usage everywhere in the program.

Can anyone tell me some important differences between them and the uses of awk.


TIA,
Nisha
# 2  
Old 06-19-2002
In shell programming all variables have the datatype string and you do not need to declare them. To assign a value to a variable you write:
varname=value

To get the value back you just put a dollar sign in front of the variable:
#!/bin/sh
# assign a value:
a="hello world"
# now print the content of "a":
echo "A is:"
echo $a

Most of the time awk is used to extract fields from a text line. The default field separator is space. To specify a different one use the option -F.

cat file.txt | awk -F, '{print $1 "," $3 }'

The comma as field separator and print the first and third ($1 $3) columns. If file.txt has lines like:
Bor, 34, India
Miller, 22, USA

then this will produce:
Bor, India
Miller, USA


There is much more you can do with awk but this is a very common use.
# 3  
Old 06-19-2002
Hey thanks ... but can i replace an awk programming with shell programming and vice versa?
# 4  
Old 06-19-2002
The original shell was the bourne sh. It had limited capabilities and was designed to lean very heavily on external programs. It had almost no built-in functions. The authors of awk wrote awk in this environment. And they stated roughly that awk was intended to greatly extend the kinds of shell scripts that can be written.

The first shells were written before awk was written. awk was never intended to be a new shell. awk was intended by its authors to work with shells, not replace them.

Both awk and the shells are now much more powerful. You can write stand-alone awk programs. And you can even write stand-alone sed programs for that matter. But both awk and sed are generally used inside of a shell script.

When I wrote in the the bourne shell, I leaned on awk very heavily. But I always saw awk as a crutch for a weak shell. Now that I have switched to the korn shell, I almost never use awk anymore.

But that's just me. Other folks really like awk and use it extensively. Unix has many tools and there are many ways to do most things. You really need to survey the tools and pick your own favorite.

I will say this though, no one uses awk for a login shell. awk programmers will need to know a shell well enough to at least log in.
# 5  
Old 06-20-2002
Smilie Think about it...
If you can use sh shell in your own unix system, but you not sure it can work fine in other system...vice versa
You wrote a program by awk, that is.. on both system running wellSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk programming -Passing variable to awk for loop

Hi All, I am new to AWK programming. I have the following for loop in my awk program. cat printhtml.awk: BEGIN -------- <some code here> END{ ----------<some code here> for(N=0; N<H; N++) { for(M=5; M<D; M++) print "\t" D ""; } ----- } ... (2 Replies)
Discussion started by: ctrld
2 Replies

2. Shell Programming and Scripting

awk programming

Need assistance using awk . Need assistance in awk programming. Any idea of getting the marked data into a file. </tr> <tr> <td class='labelOptional_ind'> cdr.00012325.0000000000000000.20130612.050005.WANP4722_csv </td> <td width='15%' class='labelOptional'> <div align='center'>... (8 Replies)
Discussion started by: ajayram_arya
8 Replies

3. Shell Programming and Scripting

AWK programming

Hi All, I read the AWK manual in the MAN page. But i didn't understand the below piece of code in the script TABLE=`echo "${FILE}" | awk -F"/" '{print $NF}' | cut -d"." -f1 | awk -F"_" '{print $NF}' 2>> ${LOGFILE}`; Please explain the above code. Thanks in advance ....... Regards,... (4 Replies)
Discussion started by: pdathu
4 Replies

4. Programming

awk programming

I have the list of numbers in a file 105.1 102.0 100.5 100 98 97.5 95 ... I want to get how many times I have numbers greater than a particular limit, say 100 in the list. How can I do that with awk command? (5 Replies)
Discussion started by: pranto_d
5 Replies

5. Shell Programming and Scripting

awk programming

Good morning to everyone! guys, help me please I have a file like this one: diamond 5 7.8 77777765 1 7 1234567890 9 3.5 diamond 2 1 1234567890 3 6.8 77777765 0 4 os Solaris it's only example, columns may be more, but in my case only 3 columns so, my question how I can group... (1 Reply)
Discussion started by: shizik
1 Replies

6. UNIX for Dummies Questions & Answers

awk programming

Good morning! guys, help me please I have a file like this one: diamond 5 7.8 77777765 1 7 1234567890 9 3.5 diamond 2 1 1234567890 3 6.8 77777765 0 4 os Solaris it's only example, columns may be more, but in my case only 3 columns so, my question how I can group according to... (1 Reply)
Discussion started by: shizik
1 Replies

7. Shell Programming and Scripting

awk programming

Hi I have a multi -line file which is sorted by the 1-st colomn in the following format: 400 0000 0001 1000 1010 0111 0000 1000 0000 402 1101 0000 1100 1010 0111 1000 1000 0000 403 1001 0000 1100 1010 0111 0000 1000 0000 495 1000 0000 1100 ... (4 Replies)
Discussion started by: aoussenko
4 Replies

8. UNIX for Dummies Questions & Answers

awk (?) programming

Hello i need help with following problem: i need to update a file containing records in following format: student1 classa student2 classb student3 student4 classc i need to associate EACH student with a class in my output file ... so for students 3 and 4, i need to create a... (12 Replies)
Discussion started by: alrinno
12 Replies

9. Shell Programming and Scripting

need help with awk programming

Hello Friends I want to process only those lines which are not started with a * or " example File name: GRX "RxDataTime, NSysClkEn, Frame","Size","Sleep","TNum","TSet","TWait" *Init Start *Comment Generated from: C:\Documents and Settings 000000,0000,1,0,0,0,0,0,0... (8 Replies)
Discussion started by: user_prady
8 Replies

10. Shell Programming and Scripting

awk programming

Hi all, i want to study harder awk programming. where can i get a good examples, problems and solutions. i'm in a hurry.. thanks, (5 Replies)
Discussion started by: tungaw2004
5 Replies
Login or Register to Ask a Question