getopts won't let him use long arguments like --help, though
I think this can be fixed simply enough, anyway. Ditch the argument with shift first, then use "$@" to get all remaining options.
I'd have built the program a little differently though, putting the actual operations outside the loop, but it looks like you're planning on doing that anyway. You don't have to test for every combination of -a, -ar, -n, -nr though, you can process the 'a', 'r', 'n' individually:
Here's what the shell (korn) script is doing:
1. Prompt for input
2. Read a file using the cat and the while read command.
3. Get a field on the record and hold that value in a variable.
4. Within the process, I then need to prompt the user again to ask them if they are sure they want to make... (3 Replies)
Hello,
So I sorted my file as I was supposed to:
sort -n -r -k 2 -k 1 file1 | uniq > file2
and when I wrote
> cat file2
in the command line, I got what I was expecting, but in the script itself
...
sort -n -r -k 2 -k 1 averages | uniq > temp
cat file2
It wrote a whole... (21 Replies)
Hi Everyone,
I have a file: a.txt
a,b,c,d,6,6,6
1,2,3,d,6,6,6
4,5,6,6,6,6,6
#!/usr/bin/perl
use warnings;
use strict;
my @array = ();
### Load file into array
for my $i (split '\n', `cat /tmp/a.txt`) {
push @array, ;
}
It works. But my a.txt have 1million lines, and... (2 Replies)
Hi,
I have a text file with multiple lines, each having data in the below format
<DOB>,<ADDRESS>
I have to write a script which reads each line in the text file in loop, assign the values to these variables and do some further processing in it.
Using the following code prints the... (1 Reply)
Hello...
Is it possible that we can change the format of the values we entered in a text file using cat?
Like for example, I will create a text file names.txt using cat and as I save the names and view the text file... the format will be like this
... (5 Replies)
Hi,
I still have the problem with directing information from cat or grep to a variable.
For instance:
XMSG "$(date +%Y_%m_%d)_error_report.txt" "$(cat "$(date +%Y_%m_%d)_error_report.txt")" &Works! The text received by cat is directed to my function.
If it is written like this, my... (2 Replies)
I dont even have a sample script cause I dont know where to start from. My data lookes like this
> sat#16 #data: 15 site:UNZA baseline: 205.9151
0.008 -165.2465 35.8109 40.6685 21.9148 121.1446 26.4629 -18.4976 33.8722
0.017 -165.2243 48.2201 40.6908 ... (8 Replies)
Hi,
I have a huge file that has data something like shown below:
huge_file.txt
start regexp
Name=Name1
Title=Analyst
Address=Address1
Department=Finance
end regexp
some text
some text
start regexp
Name=Name2
Title=Controller
Address=Address2
Department=Finance
end regexp (7 Replies)
I have a directory that is restricted and I cannot just copy the files need, but I can cat them and redirect them to a new directory. The files all have the date listed in them. If I perform a long listing and grep for the date (150620) I can redirect that output to a text file. Now I need to... (5 Replies)
I am trying to read some data form .key file with cat command..but its not displaying data correctly..tried with other commands also still no use.i tried with CAT with SED combination but no use..
Please help me with the command or script. (10 Replies)
Discussion started by: kish_rock
10 Replies
LEARN ABOUT SUNOS
runat
runat(1) User Commands runat(1)NAME
runat - execute command in extended attribute name space
SYNOPSIS
/usr/bin/runat file [command]
DESCRIPTION
The runat utility is used to execute shell commands in a file's hidden attribute directory. Effectively, this utility changes the current
working directory to be the hidden attribute directory associated with the file argument and then executes the specified command in the
bourne shell (/bin/sh). If no command argument is provided, an interactive shell is spawned. The environment variable $SHELL defines the
shell to be spawned. If this variable is undefined, the default shell, /bin/sh, is used.
The file argument can be any file, including a directory, that can support extended attributes. It is not necessary that this file have any
attributes, or be prepared in any way, before invoking the runat command.
OPERANDS
The following operands are supported:
file Any file, including a directory, that can support extended attributes.
command The command to be executed in an attribute directory.
ERRORS
A non-zero exit status will be returned if runat cannot access the file argument, or the file argument does not support extended
attributes.
USAGE
See fsattr(5) for a detailed description of extended file attributes.
The process context created by the runat command has its current working directory set to the hidden directory containing the file's
extended attributes. The parent of this directory (the ".." entry) always refers to the file provided on the command line. As such, it may
not be a directory. Therefore, commands (such as pwd) that depend upon the parent entry being well-formed (that is, referring to a direc-
tory) may fail.
In the absence of the command argument, runat will spawn a new interactive shell with its current working directory set to be the provided
file's hidden attribute directory. Notice that some shells (such as zsh and tcsh) are not well behaved when the directory parent is not a
directory, as described above. These shells should not be used with runat.
EXAMPLES
Example 1: Using runat to list extended attributes on a file
example% runat file.1 ls -l
example% runat file.1 ls
Example 2: Creating extended attributes
example% runat file.2 cp /tmp/attrdata attr.1
example% runat file.2 cat /tmp/attrdata > attr.1
Example 3: Copying an attribute from one file to another
example% runat file.2 cat attr.1 | runat file.1 "cat > attr.1"
Example 4: Using runat to spawn an interactive shell
example% runat file.3 /bin/sh
This spawns a new shell in the attribute directory for file.3. Notice that the shell will not be able to determine what your current direc-
tory is. To leave the attribute directory, either exit the spawned shell or change directory (cd) using an absolute path.
Recommended methods for performing basic attribute operations:
display
runat file ls [options]
read
runat file cat attribute
create/modify
runat file cp absolute-file-path attribute
delete
runat file rm attribute
permission changes
runat file chmod mode attribute
runat file chgrp group attribute
runat file chown owner attribute
interactive shell
runat file /bin/sh
or set your $SHELL to /bin/sh and
runat file
The above list includes commands that are known to work with runat. While many other commands may work, there is no guarantee that any
beyond this list will work. Any command that relies on being able to determine its current working directory is likely to fail. Examples of
such commands follow:
Example 5: Using man in an attribute directory
example% runat file.1 man runat
getcwd: Not a directory
Example 6: Spawning a tcsh shell in an attribute directory
example% runat file.3 /usr/bin/tcsh
tcsh: Not a directory
tcsh: Trying to start from "/home/user"
A new tcsh shell has been spawned with the current working directory set to the user's home directory.
Example 7: Spawning a zsh shell in an attribute directory
example% runat file.3 /usr/bin/zsh
example%
While the command appears to have worked, zsh has actually just changed the current working directory to '/'. This can be seen by using
/bin/pwd:
example% /bin/pwd
/
ENVIRONMENT VARIABLES
SHELL Specifies the command shell to be invoked by runat.
EXIT STATUS
The following exit values are returned:
125 The attribute directory of the file referenced by the file argument cannot be accessed.
126 The exec of the provided command argument failed.
Otherwise, the exit status returned is the exit status of the shell invoked to execute the provided command.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
|CSI |Enabled |
+-----------------------------+-----------------------------+
|Interface Stability |Evolving |
+-----------------------------+-----------------------------+
SEE ALSO open(2), attributes(5), fsattr(5)NOTES
It is not always obvious why a command fails in runat when it is unable to determine the current working directory. The errors resulting
can be confusing and ambiguous (see the tcsh and zsh examples above).
SunOS 5.10 22 Jun 2001 runat(1)