Give inputs externally to awk script


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Give inputs externally to awk script
# 1  
Give inputs externally to awk script

Hello to all,

Please some awk expert could help me.

If I want to run an awk script as "command" give it inputs externally I do:
Script.sh
Code:
Input="$1" # "$1" is the input that will be given to the script
Output=${Input%.*}.csv

awk '{$1=$1}1' $Input | awk '{...}' > $Output

and I run the script like this:
Code:
. Script.sh inputfile

Then, the output is inputfile.csv.

That works correctly, but now I have another awk script that uses 2 inputs as follow
awk '{...}' Inputfile1 Inputfile2

What is needed in order that the script accepts the 2 inputs externally similarly as I do with my above script? I mean
run the script like this:

Code:
. Script.sh Inputfile1 Inputfile2

Thanks in advance for any help.
# 2  
This should work if you are using Kshell or bash:

Code:
awk ' {do-something}' "$@" >output-file

If you have more than the two file names on the command line, then:

Code:
awk '{do-something}' $1 $2 >output-file

This User Gave Thanks to agama For This Post:
# 3  
Hello Agama,

Many thanks for your help.

It worsk perfect.

Last question.
The "$@" in code below is when the input is only one file?
Code:
awk ' {do-something}' "$@" > output-file

And if the inputs are more than 2 should be like this?
Code:
awk '{do-something}' $1 $2 $3 >output-file

Thanks again Smilie
# 4  
Code:
awk ' {do-something}' "$@" > output-file

will handle multiple inputs as well.
This User Gave Thanks to elixir_sinari For This Post:
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #498
Difficulty: Medium
Learning a computer programming language is harder than learning a new spoken language.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script inputs to python

Hi I am trying to pass 2 input parameters from shell script to python API end point ,but not passing what i expected when print those inputs .Please advise data.txt " 7554317" ,xx5e1 " 7554317" ,xx96 " 7554317" ,xxd6 " 554317" ,xde cat $sites/data.txt |sort |uniq >$sites/a.txt... (5 Replies)
Discussion started by: akil
5 Replies

2. Shell Programming and Scripting

Script to cp files that user inputs

Need a bash script that will ask the user: Which Files Would you like to copy? Then the user would input the filenames (space seperated, all lowercase) The script would then cp each file to /data/backup/ and also wc the files to std output. (to see how many lines each file has) Should go... (5 Replies)
Discussion started by: ajp7701
5 Replies

3. Shell Programming and Scripting

Print Unknown Number of User Inputs in awk

Hello, I am new to awk and I am trying to figure out how to print an output based on user input. For example: ubuntu:~/scripts$ steps="step1, step2, step3" ubuntu:~/scripts$ echo $steps step1, step2, step3 I am playing around and I got this pattern that I want: ... (3 Replies)
Discussion started by: tattoostreet
3 Replies

4. Shell Programming and Scripting

Taking inputs for awk

Hi, i want to print 2nd column value with the below script. I need to take input of the string i need to search in that file and file name. How can i take these two as inputs? using read command? Getting error for below script. echo "enter SID" read SID echo "enter filename" read filename... (8 Replies)
Discussion started by: sam_bd
8 Replies

5. UNIX for Dummies Questions & Answers

How to give multiple inputs to a shell script

Got struck while trying to write a shell script which should automatically give input. While running a script for eg: (adpatch.sh) It Prompts for Multiple inputs like: Do you currently have files used for installing or upgrading the database installed in this APPL_TOP ? need to give... (2 Replies)
Discussion started by: abdmoha
2 Replies

6. Shell Programming and Scripting

Perl script for taking inputs from one script and storing them into a document.

Hi. I wanted to create a Perl script which can take the outputs of a Perl script as it's input and temporarily store them in a document. Need help. Thanks.:) (8 Replies)
Discussion started by: xtatic
8 Replies

7. Shell Programming and Scripting

Need inputs on UNIX script basics

Hi UNIX Gurus, I have a SQL utility which fires DML statements against DB2 tables. Logic is to identify DML statements, put it into a file ($dml) and execute the job. DML file can have more than 1 DML statements....but all of 1 type at a time.....either all UPDATE or all DELETE. Job first... (2 Replies)
Discussion started by: ustechie
2 Replies

8. Shell Programming and Scripting

need inputs on how i can change my script to reduce amount of time the script takes

HI , I have a list1 which consists of data that i have to search and a list2 which has the files that need to be searched .So basically i am using list1 on list2 to see if list1 data is present if found replace it .I have written the code using foreach loop for each list .This is taking the... (1 Reply)
Discussion started by: madhul2002
1 Replies

9. Shell Programming and Scripting

use several inputs as arguments in my script

Hi there, It's pretty hard for me to explain my problem because I'm affraid I'm not using the correct vocabulary. So let me describe the situation. I wrote a script that has one argument. It works like this: ~$ cat /usr/local/bin/squote echo "$@" | sed 's/'\''/'\''\\'\'\''/g; s/.*/'\''&'\''/g'... (2 Replies)
Discussion started by: chebarbudo
2 Replies

10. Shell Programming and Scripting

Please give your inputs !!!!

I am trying to extract two fields from the output of ifconfig command on one of my sun server . The output looks like : root@e08k18:/tmp/test# ifconfig -a lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 ce0:... (9 Replies)
Discussion started by: kpatel786
9 Replies

Featured Tech Videos