Sponsored Content
Homework and Emergencies Homework & Coursework Questions How to implement wc command using awk? Post 302857983 by sidpatil on Friday 27th of September 2013 10:45:48 PM
Old 09-27-2013
How to implement wc command using awk?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Here in flwng code \n is not working

2. Relevant commands, code, scripts, algorithms:

Files: a.txt
This is test line
End of line

a.sh
a.awk


3. The attempts at a solution (include all code and scripts):

the code i tried;
a.sh:
awk -f a.awk a.sh

a.awk:
BEGIN{
l=0
w=0
c=0
}
{
n=length($0)
for(i=1;i<=n;i++)
{
ch=substr($0,i,1)
if(ch==" " || ch=="\n")
w++
else if(ch=="\n")
l++
else
c++
}
}
END{
print("lines=",l)
print("words=",w)
print("characters",c)
}


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Sp university
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how can i implement rlogin

how can i use a rlogin with out entered a password, someone tell me about configure the next files /.rhosts /etc/hosts.equiv and /etc/hosts but i not sure about that, or there are not enough could you tell me how to do that? (3 Replies)
Discussion started by: jav_v
3 Replies

2. Shell Programming and Scripting

how to implement this

Hi all, could any of you please help me on my problem.. we are doing FTP (one report out put) from one server to another server through unix shell script program. Due to the network issues, some times FTP process is hanging. So we planned to modify the existing program with the following... (2 Replies)
Discussion started by: kishore_jasthi
2 Replies

3. Shell Programming and Scripting

Trying to implement 'more' command

Hi all, i'm quite new in the UNIX world. So maybe i'm going to ask simple questions but they are unsolvable for me... I'm trying to implement the 'more' function or kinda of that, for improving my knowledges. But I encountered some problems that i hope u will help me to solve. The code i... (0 Replies)
Discussion started by: Cellofan
0 Replies

4. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

5. Shell Programming and Scripting

How to implement this?

hi i have a file like 1,"A","B" 2,"C","D" 1,"E","F" 3,"G","H" in output i need like 3,"G","H" 1,"E","F" 2,"C","D" 1,"A","B" (12 Replies)
Discussion started by: angel12345
12 Replies

6. Shell Programming and Scripting

how to implement in one-line awk in a fixed file having no delimiter

Hi, I have a file a.txt having no delimiter. I want to exclude the line which contains 435th character as 1 or 2 and redirect the rest of the lines to another file b. Can you pls suggest how to do this in one liner awk. Following is just one line of the input file a:- 120110116 ... (10 Replies)
Discussion started by: millan
10 Replies

7. Shell Programming and Scripting

Implement in one line sed or awk having no delimiter and file size is huge

I have file which contains around 5000 lines. The lines are fixed legth but having no delimiter.Each line line contains nearly 3000 characters. I want to delete the lines a> if it starts with 1 and if 576th postion is a digit i,e 0-9 or b> if it starts with 0 or 9(i,e header and footer) ... (4 Replies)
Discussion started by: millan
4 Replies

8. Shell Programming and Scripting

How to implement a command n times?

I need to run a command n (n >= 100) times and the command running may take about 30 seconds. Can anyone help me with the shell script to achieve this? Thanks in advance. (5 Replies)
Discussion started by: zwei2011
5 Replies

9. Programming

Implement ps command in C

Hello, could anybody explain how the ps command works? I know something about the proc file system. But I'm still not sure about how it exactly works. Like ps without any option will print out the current user's processes, but it never displays my web browsers such as firefox or my LibreOffice... (3 Replies)
Discussion started by: freedombird9
3 Replies

10. UNIX for Beginners Questions & Answers

How to implement a simple command/code for multiple files?

I have been extracting a row, based on multiple key word from a xls/csv file, by using the following command. I have to implement the same for multiple xls/csv files, therefore please help me to do the same. awk ' { tbp=0 if ($0 ~ keyword1 && k1 == 0) { tbp=1; k1++ } if ($0 ~ keyword2... (2 Replies)
Discussion started by: dineshkumarsrk
2 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 03:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy