Read input file with in awk script not through command line | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Read input file with in awk script not through command line

Shell Programming and Scripting


Tags
awk, awk script, shell scipting

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-21-2013
random_thoughts random_thoughts is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 18 June 2014, 9:34 AM EDT
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Read input file with in awk script not through command line

Hi All,

Do we know how to read input file within awk script and send output toanother log file. All this needs to be in awk script, not in command line. I am running this awk through crontab.


Code:
 
Cat my.awk
#!/bin/awk -f
function test(var){
some code}
{
}
END
{
print"test code"
}

Sponsored Links
    #2  
Old 06-21-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 28 July 2014, 9:58 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,215
Thanks: 120
Thanked 450 Times in 410 Posts
What do you want to achieve?
Just some simple redirection for which you do not need awk at all, or
plain processing of a file by awk and redirecting the output, or
processing a file of input with awk while having a 2nd file being processed too?
Sponsored Links
    #3  
Old 06-21-2013
random_thoughts random_thoughts is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 18 June 2014, 9:34 AM EDT
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Processing a file of input and redirecting the output to another file. How Would I put input file name and out put file name in awk script, not thru command line
    #4  
Old 06-21-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 28 July 2014, 9:58 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,215
Thanks: 120
Thanked 450 Times in 410 Posts
I am not sure if I understand - the explanation seems so simple in regards to your former thread http://www.unix.com/shell-programmin...ent-lines.html

Anyway, you use awk in a shell script the same way as you do that in a shell.
In your code like example, you used -f to give awk a script file. The last argument is always the file name of the file to be processed (for example data, logs...).


Code:
awk '{print $1}' infile > outfile
#or
awk '{print $1 >> outfile}' infile

I am not sure if this hits what you are looking for - else a bit more detailed explanation could help, or maybe another poster understands it, sorry.
Sponsored Links
    #5  
Old 06-21-2013
random_thoughts random_thoughts is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 18 June 2014, 9:34 AM EDT
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks, Assumes input file name is test.log on which my.awk script runs and it gives output to output.log

I can run this script by this command through command line

Code:
./my.awk test.log > output.log

How can I put this test.log and output.log in my.awk so that if I run below command it should work.

Code:
./my.awk



Code:
 
Cat my.awk
#!bin/awk -f
function(time){
}
{
action####
}
END{
print(""')
}

Sponsored Links
    #6  
Old 06-21-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 28 July 2014, 9:58 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,215
Thanks: 120
Thanked 450 Times in 410 Posts
I see no easy way to do that, that is not awkward. Neither do I see a reason why this has to be done. What is the reason if I may ask? Why not just use a shell script that calls awk?

Maybe someone else has an idea how to do that the way you want it.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash script to delete file input on command line animesharma UNIX for Dummies Questions & Answers 1 07-21-2011 04:27 AM
awk script file command line options tomr2k Shell Programming and Scripting 2 06-30-2011 02:55 AM
sed to read line by line and input into another file dolacap Shell Programming and Scripting 3 07-08-2010 10:48 AM
How can I send the input of a read line command through a shell script little_wonder Shell Programming and Scripting 6 07-21-2009 06:38 AM
read a file as input and pass each line to another script sajjad02 Shell Programming and Scripting 0 09-24-2004 11:13 PM



All times are GMT -4. The time now is 04:30 PM.