The sample inputs and output shown in post #7 in this thread shows headers in both input files and in the output file that are not handled by the code shown in any of your posts. The output shown in post #7 does not contain any data shown in either of the input files in post #7. The format of the output shown in post #7 seems to have complete lines from the input files, but your code only copies three fields from the input files to the output file. So, with absolutely no idea what is really supposed to be done by your awk code and no data that can be used for testing, the following has undergone completely unrealistic testing, but may give you an idea of how to write a shell and awk script that grabs related files from two directories and produces related output files in a third directory.
This was written and tested using a Korn shell, but this will also work with bash or any other shell that uses Bourne shell syntax AND performs parameter expansions required by the POSIX standards.
This User Gave Thanks to Don Cragun For This Post:
HI
I am trying to store the output of this awk command
awk -F, {(if NR==2) print $1} test.sr
in a variable when I am trying v= awk -F, {(if NR==2) print $1} test.sr
$v = awk -F, {(if NR==2) print $1} test.sr
but its not working out .
Any suggestions
Thanks
Arif (3 Replies)
Hi,
i have some files in one directory(say some sample dir) whose names will be like the following.
some_file1.txt
some_file2.txt.
i need to get the last modified file size based on file name pattern like some_
here i am able to get the value of the last modified file size using the... (5 Replies)
Hi folks,
I'm using bash and would like to do the following. I would like to read some values from the file and store it in the variable and use it.
My file is 1.txt and its contents are
VERSION=5.6
UPDATE=4
I would like to read "5.6" and "4" and store it in a variable in shell... (6 Replies)
i want to store the output of 'tail -5000 file' to a variable.
If i want to access the contents of that variable, it becomes kinda difficult because when the data is stored in the variable, everything is mushed together. you dont know where a line begins or ends.
so my question is, how can i... (3 Replies)
Hi all, im having snags creating a variable which uses commands like cut and grep. In the instance below im simply trying to take a value from another file and assign it to a variable. When i do this it only prints the $a rather than the actual value. I know its simple but does anyone have any... (1 Reply)
I am working on a script for Mac OS X that, among many other things, gets a list of all the installed Applications. I am pulling the list from the system_profiler command and formatting it using grep and awk. The problem is that I want to be able to use each result individually later in the script.... (3 Replies)
Hi,
My aim is to get the md5 hash of a file and store it in a variable.
var1="md5sum file1"
$var1
The above outputs fine but also contains the filename, so somthing like this 243ASsf25 file1
i just need to get the first part and put it into a variable.
var1="md5sum file1"... (5 Replies)
I'm working on a script in which gives certain details in its output depending on user-specified options. So, what I'd like to do is something like:
if
then
awkcmd='some_awk_command'
else
awkcmd='some_other_awk_command'
fi
Then, later in the script, we'd do something like:
... (5 Replies)
Hi All,
I was trying a shell script. I was unable to store file contents to a variable in the script. I have tried the below but unable to do it.
Input = `cat /path/op.diary`
Input = $(<op.diary)
I am using ksh shell. I want to store the 'op.diary' file contents to the variable 'Input'... (12 Replies)
Discussion started by: am24
12 Replies
LEARN ABOUT OSX
cat
CAT(1) BSD General Commands Manual CAT(1)NAME
cat -- concatenate and print files
SYNOPSIS
cat [-benstuv] [file ...]
DESCRIPTION
The cat utility reads files sequentially, writing them to the standard output. The file operands are processed in command-line order. If
file is a single dash ('-') or absent, cat reads from the standard input. If file is a UNIX domain socket, cat connects to it and then reads
it until EOF. This complements the UNIX domain binding capability available in inetd(8).
The options are as follows:
-b Number the non-blank output lines, starting at 1.
-e Display non-printing characters (see the -v option), and display a dollar sign ('$') at the end of each line.
-n Number the output lines, starting at 1.
-s Squeeze multiple adjacent empty lines, causing the output to be single spaced.
-t Display non-printing characters (see the -v option), and display tab characters as '^I'.
-u Disable output buffering.
-v Display non-printing characters so they are visible. Control characters print as '^X' for control-X; the delete character (octal
0177) prints as '^?'. Non-ASCII characters (with the high bit set) are printed as 'M-' (for meta) followed by the character for the
low 7 bits.
EXIT STATUS
The cat utility exits 0 on success, and >0 if an error occurs.
EXAMPLES
The command:
cat file1
will print the contents of file1 to the standard output.
The command:
cat file1 file2 > file3
will sequentially print the contents of file1 and file2 to the file file3, truncating file3 if it already exists. See the manual page for
your shell (i.e., sh(1)) for more information on redirection.
The command:
cat file1 - file2 - file3
will print the contents of file1, print data it receives from the standard input until it receives an EOF ('^D') character, print the con-
tents of file2, read and output contents of the standard input again, then finally output the contents of file3. Note that if the standard
input referred to a file, the second dash on the command-line would have no effect, since the entire contents of the file would have already
been read and printed by cat when it encountered the first '-' operand.
SEE ALSO head(1), more(1), pr(1), sh(1), tail(1), vis(1), zcat(1), setbuf(3)
Rob Pike, "UNIX Style, or cat -v Considered Harmful", USENIX Summer Conference Proceedings, 1983.
STANDARDS
The cat utility is compliant with the IEEE Std 1003.2-1992 (``POSIX.2'') specification.
The flags [-benstv] are extensions to the specification.
HISTORY
A cat utility appeared in Version 1 AT&T UNIX. Dennis Ritchie designed and wrote the first man page. It appears to have been cat(1).
BUGS
Because of the shell language mechanism used to perform output redirection, the command ``cat file1 file2 > file1'' will cause the original
data in file1 to be destroyed!
The cat utility does not recognize multibyte characters when the -t or -v option is in effect.
BSD March 21, 2004 BSD