Sponsored Content
Full Discussion: Multiple varibles in file
Top Forums Shell Programming and Scripting Multiple varibles in file Post 302423959 by numele on Sunday 23rd of May 2010 09:48:34 PM
Old 05-23-2010
Multiple varibles in file

Working on a way to speed up my script output. I have a multiline file that I pull each line as a variable and post it on a webpage. It needs some help as it works but slow. I think I have too many cat, grep and sed going on but don't know what would work better.
Code:
#!/bin/sh
FILE=/export/htdocs/request/$REQUEST
DATE=`cat $FILE | grep "DATE=" | sed -n 's/.*=//p'`
NAME=`cat $FILE | grep "NAME=" | sed -n 's/.*=//p'`
EMAIL=`cat $FILE | grep "EMAIL=" | sed -n 's/.*=//p'`
PHONE=`cat $FILE | grep "PHONE=" | sed -n 's/.*=//p'`
UID=`cat $FILE | grep "UID=" | sed -n 's/.*=//p'`
COMPANY=`cat $FILE | grep "COMPANY=" | sed -n 's/.*=//p'`
OC=`cat $FILE | grep "OC=" | sed -n 's/.*=//p'`
PRIORITY=`cat $FILE | grep "PRIORITY=" | sed -n 's/.*=//p'`
EXPLAIN=`cat $FILE | grep "EXPLAIN=" | sed -n 's/.*=//p'`
JUSTIFICATION=`cat $FILE | grep "JUSTIFICATION=" | sed -n 's/.*=//p'`
COMMENTS=`cat $FILE | grep "COMMENTS=" | sed -n 's/.*=//p'`
REGION=`cat $FILE | grep "REGION=" | sed -n 's/.*=//p'`
ADD_DELETE=`cat $FILE | grep "ADD_DELETE=" | sed -n 's/.*=//p'`
FILTER=`cat $FILE | grep "FILTER=" | sed -n 's/.*=//p'`
TYPE=`cat $FILE | grep "TYPE=" | sed -n 's/.*=//p'`
SOURCE_IP=`cat $FILE | grep "SOURCE_IP=" | sed -n 's/.*=//p'`
PORT=`cat $FILE | grep "PORT=" | sed -n 's/.*=//p'`
STATUS=`cat $FILE | grep "STATUS=" | sed -n 's/.*=//p'`

Here is a sample file it is pulling from
Code:
NAME=John Smith
EMAIL=jsmith@testmail.com
PHONE=212-555-1212
UID=gg1234
COMPANY=OTHER
OC=ABC Company
REGION=All
ADD_DELETE=Add
FILTER=Mail
SERVICE_TYPE=TCP
SOURCE_IP=10.1.1.1
PORT=25
REGION=All
ADD_DELETE=Delete
FILTER=Router Access
SERVICE_TYPE=TCP
SOURCE_IP=192.168.1.0/24
PORT=23
PRIORITY=Normal
EXPLAIN=This is an example explanation
JUSTIFICATION=Business justification description
COMMENTS=No comments
DATE=05/23/2010
STATUS=Pending

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

environmental varibles

flavor -- AIX 4.2.1 I am putting together some HTML pages, some of which contain forms. The problem pops up when I attempt to pass variables (from the forms) from one HTML page to a cgi-like page created using ksh. I have used the $1 - $9 vars, but they do not work with the passing. With... (1 Reply)
Discussion started by: Xiix
1 Replies

2. Shell Programming and Scripting

Dynamic Varibles problem

All, Any chance someone could help me with this.... The script is reading from a file and for every line of input to the loop I am trying to assign a new varible. When i run the script I get the below errors. I have come to a bit of a dead end so any pointers/help would be very much... (1 Reply)
Discussion started by: oconnon2
1 Replies

3. UNIX for Dummies Questions & Answers

different way to echo varibles...help

Given the following loop: foreach id (DB4 GH4 CD4) and the previously defined variables: DB4sf DB4sfk DB4pp GH4sf GH4sfk GH4pp CD4sf CD4sfk CD4pp how do i echo all of these variables using a one line command in the for loop. If it was a script, and assuming the previously mentioned... (8 Replies)
Discussion started by: wxornot
8 Replies

4. UNIX for Dummies Questions & Answers

How to create ENV varibles

Hi, I want create env variable for "/ramakrsihna/scripts" help me on this. (1 Reply)
Discussion started by: koti_rama
1 Replies

5. Shell Programming and Scripting

split varibles and store fields into shell varible array

I need to split a long varible which is a whole line read from a file into fields and store them in an array, the fields are delimited by pipe and a field may contain white spaces. I tried the following concept test and it has problem with field 5 which contain a space, appearently so because... (3 Replies)
Discussion started by: gratus
3 Replies

6. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

7. Shell Programming and Scripting

Passing varibles as a string argument ?

For example test.sh: test="teststring" cmd=$1 $cmd For some reason I'm NOT seeing "teststring" when I type: ./test.sh "echo $test" Any ideas on how to get around this? I've tried commands like: ./test.sh "echo $($test)" ./test.sh "echo '$test'" And many variations to no... (6 Replies)
Discussion started by: secops
6 Replies

8. UNIX for Dummies Questions & Answers

Need Help Setting Path and Environment Varibles

Hello all, I have a Mac OS X (10.7), and I need to set environment variables and paths for some programs I will be running. I have followed instructions and searched the Web for where to do this, but I can't seem to find an answer. I have tried using the VIM editor to write them into my .login,... (2 Replies)
Discussion started by: Tyler_92
2 Replies

9. Shell Programming and Scripting

Grep and replace multiple strings in a file with multiple filenames in a file

Hi, I have a file containing list of strings like i: Pink Yellow Green and I have file having list of file names in a directory j : a b c d Where j contains of a ,b,c,d are as follows a: Pink (3 Replies)
Discussion started by: madabhg
3 Replies

10. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies
OSASCRIPT(1)						    BSD General Commands Manual 					      OSASCRIPT(1)

NAME
osascript -- execute OSA scripts (AppleScript, JavaScript, etc.) SYNOPSIS
osascript [-l language] [-i] [-s flags] [-e statement | programfile] [argument ...] DESCRIPTION
osascript executes the given OSA script, which may be plain text or a compiled script (.scpt) created by Script Editor or osacompile(1). By default, osascript treats plain text as AppleScript, but you can change this using the -l option. To get a list of the OSA languages installed on your system, use osalang(1). osascript will look for the script in one of the following three places: 1. Specified line by line using -e switches on the command line. 2. Contained in the file specified by the first filename on the command line. This file may be plain text or a compiled script. 3. Passed in using standard input. This works only if there are no filename arguments; to pass arguments to a STDIN-read script, you must explicitly specify ``-'' for the script name. Any arguments following the script will be passed as a list of strings to the direct parameter of the ``run'' handler. For example, in AppleScript: a.scpt: on run argv return "hello, " & item 1 of argv & "." end run % osascript a.scpt world hello, world. The options are as follows: -e statement Enter one line of a script. If -e is given, osascript will not look for a filename in the argument list. Multiple -e options may be given to build up a multi-line script. Because most scripts use characters that are special to many shell programs (for example, AppleScript uses single and double quote marks, ``('', ``)'', and ``*''), the statement will have to be correctly quoted and escaped to get it past the shell intact. -i Interactive mode: osascript will prompt for one line at a time, and print the result, if applicable, after each line. Any script sup- plied as a command argument using -e or programfile will be loaded, but not executed, before starting the interactive prompt. -l language Override the language for any plain text files. Normally, plain text files are compiled as AppleScript. -s flags Modify the output style. The flags argument is a string consisting of any of the modifier characters e, h, o, and s. Multiple modi- fiers can be concatenated in the same string, and multiple -s options can be specified. The modifiers come in exclusive pairs; if con- flicting modifiers are specified, the last one takes precedence. The meanings of the modifier characters are as follows: h Print values in human-readable form (default). s Print values in recompilable source form. osascript normally prints its results in human-readable form: strings do not have quotes around them, characters are not escaped, braces for lists and records are omitted, etc. This is generally more useful, but can introduce ambiguities. For example, the lists '{"foo", "bar"}' and '{{"foo", {"bar"}}}' would both be displayed as 'foo, bar'. To see the results in an unambiguous form that could be recompiled into the same value, use the s modifier. e Print script errors to stderr (default). o Print script errors to stdout. osascript normally prints script errors to stderr, so downstream clients only see valid results. When running automated tests, how- ever, using the o modifier lets you distinguish script errors, which you care about matching, from other diagnostic output, which you don't. SEE ALSO
osacompile(1), osalang(1), AppleScript Language Guide HISTORY
osascript in Mac OS X 10.0 would translate ' ' characters in the output to ' ' and provided c and r modifiers for the -s option to change this. osascript now always leaves the output alone; pipe through tr(1) if necessary. Prior to Mac OS X 10.4, osascript did not allow passing arguments to the script. Mac OS X April 24, 2014 Mac OS X
All times are GMT -4. The time now is 07:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy