LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-11-2015, 05:58 AM   #1
rimonece
LQ Newbie
 
Registered: Jun 2015
Location: Perth, WA
Posts: 22

Rep: Reputation: Disabled
How to create a batch script for running awk file with trace in NS2?


I have a tcl file including the queue-limit of a particular link. I want to vary this queue-limit(20 times) and run by the same awk file.

Code:
$ns simplex-link $eNB $UE($i) 10Mb 2ms LTEQueue/DLAirQueue 
$ns queue-limit $eNB $UE($i) 100

In Shell, I am running

Code:
 /ns2-35/ ns 22.tcl > 22.txt; gawk -f 22.awk 22.tr
How to create a batch script for this one and run? Is it possible to get the output straight export to an excel file?

Last edited by rimonece; 11-11-2015 at 06:07 AM.
 
Old 11-13-2015, 03:32 PM   #2
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Whatever command works in the shell, you can just put it into a textfile that starts with
Code:
#!/bin/sh
make that executable with
Code:
chmod +x /path/to/file
and run it. Your command uses relative paths, so either you'll want to change it to use absolute paths or put your script into the same directory as the awk scripts and run it there.

If you want the command to run twenty times you could either
a) put the command 20 times into your script (very unelegant, but maybe a good place to start for a newbie)
b) look into the syntax of loops in shell scripts.

As far as outputting to excel format: No simple way that I am aware of, but depending on the output of your command you could probably output as csv, which can then be imported to excel. Maybe your command is already doing that (impossible for me to tell as I don't know ns and can't see your awk scripts), so if you want to pipe the result of your command to a text file you can use a so-called redirection operator (> or >>):
Code:
command > outputfile.csv
Depending on the redirection operator you will
  • > : create a new output file, overwriting an existing one if any
  • >> : append to an existing output file if it already exists or create it otherwise

One last side note: The first line of the script I mentioned above gives you a basic shell, which you can be reasonably sure will be available on any linux distro out there. For more complex scripts it's sometimes useful to use bash instead:
Code:
#!/bin/bash
I use that all the time and find it more convenient to use than plain sh, but it is less portable so some people will recommend against it.
 
2 members found this post helpful.
Old 11-13-2015, 06:28 PM   #3
rimonece
LQ Newbie
 
Registered: Jun 2015
Location: Perth, WA
Posts: 22

Original Poster
Rep: Reputation: Disabled
@joe_2000

Thank you so much. I solved my problem by using your direction.
 
Old 11-14-2015, 11:41 AM   #4
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by rimonece View Post
@joe_2000

Thank you so much. I solved my problem by using your direction.
You are welcome :-)
 
Old 11-17-2015, 08:20 PM   #5
rimonece
LQ Newbie
 
Registered: Jun 2015
Location: Perth, WA
Posts: 22

Original Poster
Rep: Reputation: Disabled
Procedure:

1. Let, a directory : ( cd/folder_1/code_1) and keep all tcl and awk file there.
2. Open a file in gedit and write the following code:

Code:
#!/bin/bash
# My first script

tcl_file=('10_0.tcl' '10_1.tcl' '10_2.tcl' '10_3.tcl' '10_4.tcl')
tr_file=('10_0.tr' '10_1.tr' '10_2.tr' '10_3.tr' '10_4.tr')
awk_file=('10_0.awk' '10_1.awk' '10_2.awk' '10_3.awk' '10_4.awk')
txt_file=('10_0.txt' '10_1.txt' '10_2.txt' '10_3.txt' '10_4.txt')


for i in {0..4}
do
	echo 'Start==================Start'$i;
	ns ${tcl_file[$i]} > ${txt_file[$i]}	
	gawk -f ${awk_file[$i]} ${tr_file[$i]} 
	echo 'End====================End'$i;
done

3. Save as mmr.sh in a directory ( cd/folder_1/code_1)
4. run : chmod 777 mmr.sh
5. From that directory, run: ./mmr.sh
 
1 members found this post helpful.
  


Reply

Tags
awk-ns2, ns2



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk script on a trace file doesnot give actual value shivee Linux - Networking 2 10-01-2015 10:14 AM
[SOLVED] awk script for caluclating throughput (trace file of ns2) rc49 Programming 6 09-28-2015 05:03 PM
running nam file in ns2 it gives warning as trace file events are not sorted by time s20 Linux - Software 0 07-19-2013 09:45 PM
Can someone help me to create a script that works like this batch file? Mysticle31 Programming 12 12-22-2007 06:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration