07-17-2012
Read 2 lines from File, Run Command based off output
Okay, so I have a file containing line after line of three digit numbers. I need a script that does an action based on the last two numbers in this list.
So.... To get the last two numbers, I can have the script do
tail -2 filename.txt
But where I run into trouble is as follows. If these last two numbers, retrieved via tail, are Greater than 400, I want to run a command. The command is irrelevant, so lets just make something up: touch filename.txt
If it helps, it doesnt necessarily have to do > 400. It would still meet my needs if it did something more like. If = 400 or 401 or 402 or 403 or 404 or 405 as there will really only be that number set, with nothing over 405.
So the script can function with whatever is easier.
Thanks a ton!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi. I'm trying to write a script that reads a line on a file and runs a different command for a different line output.
For example, if it finds the word "Kuku" on the line it sends mail to Kuku@kuku.com. Otherwise, it sends mail to Lulu@lulu.com.
TIA. (2 Replies)
Discussion started by: Doojek9
2 Replies
2. UNIX for Dummies Questions & Answers
I use the cat command to concatenate text files, but one of the rows I was expecting doesn't display in the output file. Is there a verbose mode\logging mechanism for the cat command to help me investigate where the lines I was expecting are going??
cat 7760-001_1_*_06_*.txt | grep -v... (1 Reply)
Discussion started by: Xin Xin
1 Replies
3. UNIX for Dummies Questions & Answers
Hi,
how do I read in a file which includes a list of workstations and then run a command for each workstation ?
I am unclear which command to use to read in , or is this not possible ?
Thanks, (3 Replies)
Discussion started by: manni2
3 Replies
4. Shell Programming and Scripting
Hi I would appreciate your help with this.
I have a output file from a command. It is broken based on initial of the users. Exmaple of iitials MN & SS. Under each section there is information pertaining to the user however each section can have different number of lines. MY challenge is to ... (5 Replies)
Discussion started by: mnassiri
5 Replies
5. Shell Programming and Scripting
Hi,
I need help with this-
input.txt :
L B white
X Y white
A B brown
M Y black
Read this input file and if 3rd column is "white", then add specific lines to another file insert.txt.
If 3rd column is brown, add different set of lines to insert.txt, and so on.
For example, the given... (6 Replies)
Discussion started by: prashob123
6 Replies
6. Shell Programming and Scripting
OS : Red Hat Linux 6.4
Shell : Bash
We have a file called status.txt which will have only 1 line. The content will be the string "Processing" for most of the day.
# cat status.txt
Processing
#I want to write a shell script (notify.sh) which will be executing a grep every 10 minutes .
... (7 Replies)
Discussion started by: kraljic
7 Replies
7. Shell Programming and Scripting
Hi
I have jobs (some 1000) defined in a file and I want to read those jobs and run a a command.
For example:
jobs.txt
abc
efg
I want to read the entire file and run the following command
Delete -JOB "abc"
Deleteing abc...
Delete -JOB "efg"
Delete efg...
Can somebody help me... (4 Replies)
Discussion started by: karan8810
4 Replies
8. Shell Programming and Scripting
Sample Data
#cat /mylist.txt
/raid/job/123
/raid/job/456
/raid/job/789
#
Script
#cat /myfind.scr
#!/bin/bash
touch /nojob.txt
touch /job.txt
unset dirfolder
for dirfolder in `/bin/cat /mylist.txt`;do
if
then
echo $dirfolder >>/job.txt
else
echo $dirfolder >>/nojob.txt (3 Replies)
Discussion started by: crowman
3 Replies
9. Shell Programming and Scripting
hi,
i'm trying to write a tcsh script that reads in a text file (one column) and the runs a different command for each line of text.
i've found lots of example commands for bash, but not for tcsh.
can anyone give me a hint?
thanks,
jill (8 Replies)
Discussion started by: giuinha
8 Replies
10. Programming
Experts,
I am writing a script and able to write only small piece of code and not able to collect logic to complete this task.
In input file have to look for name like like this (BGL_HSR_901_1AG_A_CR9KTR10) before sh iss neors. Record this (BGL_HSR_901_1AG_A_CR9KTR10) in csv file
Now have to... (0 Replies)
Discussion started by: as7951
0 Replies
LEARN ABOUT DEBIAN
ns_returnfp
ns_return(3aolserver) AOLserver Built-In Commands ns_return(3aolserver)
__________________________________________________________________________________________________________________________________________________
NAME
ns_connsendfp, ns_respond, ns_return, ns_returnadminnotice, ns_returnbadrequest, ns_returnerror, ns_returnfile, ns_returnforbidden,
ns_returnfp, ns_returnnotfound, ns_returnnotice, ns_returnredirect, ns_returnunauthorized, ns_write - commands
SYNOPSIS
ns_connsendfp fp len
ns_respond
ns_return status type string
ns_returnadminnotice status msg ?longmsg?
ns_returnbadrequest reason
ns_returnerror status msg
ns_returnfile status type filename
ns_returnforbidden
ns_returnfp status type fileid len
ns_returnnotfound
ns_returnnotice status msg ?longmsg?
ns_returnredirect location
ns_returnunauthorized
ns_write string
_________________________________________________________________
DESCRIPTION
These procedures provide a simple interface for returning information to the client. They build HTTP/1.0 headers and send the appropriate
data out the socket to the client. The script does not end at the time ns_return* is invoked so you can continue processing data after the
client has gotten the data and closed the socket.
type should be a MIME type (see ns_guesstype manual page for a list). status is a three-digit number fitting the pattern below: 1xx Infor-
mational - Not used, but reserved for future use. 2xx Success - The action was successfully received, understood, and accepted. 3xx Redi-
rection - Further action must be taken in order to complete the request. 4xx Client Error - The request contains bad syntax or cannot be
fulfilled. 5xx Server Error - The server failed to fulfill an apparently valid request. Some common status values and their meanings are:
201 Created 202 Accepted 203 Provisional Information 204 No Content 300 Multiple Choices 301 Moved Permanently 302 Moved Temporarily 303
Method 304 Not Modified 401 Unauthorized 402 Payment Required 403 Forbidden 404 Not Found 405 Method Not Allowed 406 None Acceptable 407
Proxy Authentication Required 408 Request Time-out 409 Conflict 410 Gone 501 Not Implemented 502 Bad Gateway 503 Service Unavailable 504
Gateway Time-out ns_connsendfp
This function writes len bytes of the specified channel or file to the conn.
ns_return
Sends back both the headers and the string.
ns_returnadminnotice
Wraps the text msg and longmsg in some html, appends a line with a link to "mailto:serveradministrator" based on the virtual server
parameter "WebMaster".
ns_returnbadrequest
Returns a 400 status code and a formatted HTML message containing the reason text.
ns_returnerror
Wraps the text msg in some html and returns that to the client.
ns_returnfile
Sends back the headers and the contents of the file.
ns_returnforbidden
Returns a 403 status code.
ns_returnfp
First sends the appropriate headers. Next, it writes out the contents of file from the current file position until the end of the
file.
ns_returnnotfound
Returns a 404 status code.
ns_returnnotice
Wraps teh text msg and longmsg in some html and returns that to the client.
ns_returnredirect
Returns a redirect to the passed in location
ns_returnunauthorized
Returns a 401 status code
ns_write
Writes the string out the connection. You can use it instead of the ns_return or ns_respond functions to build HTTP responses.
AOLserver will not include the usual headers on the output data. The script does not end at the time ns_write* is invoked so you can
continue processing data after the client has gotten the data and closed the socket.
SEE ALSO
ns_respond(n), ns_writefp(n)
KEYWORDS
AOLserver 4.0 ns_return(3aolserver)