Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Tcsh command for assigning output of awk to variable Post 302901957 by violin on Friday 16th of May 2014 04:00:10 PM
Old 05-16-2014
Tcsh command for assigning output of awk to variable

Hi I have a text file with 2 values and I am trying to assign each value to a variable and then write those to text files.

So if the textfile is data.txt with 2 values x and y

I want to assign mean=x, and stdev=y and then write these out in text files alongwith the id ($id has already been set earlier on in a larger script).

say
Code:
 echo $mean $id > mean.$id.text
     echo $stdev $id > stdev.$id.text

later on I want to go through and concatenate all the mean values for all id's into 1 file and similarly create another one for stdev.
so far I tried this (after looking through various threads)---
Code:
        mean=$( awk '{ print $1}' data.txt)
	echo $mean $id  > mean.txt

doesn't work, says illegal variable name.



thanks for any help.

Moderator's Comments:
Mod Comment Please use code tags for all code and data

Last edited by vbe; 05-16-2014 at 05:15 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning output of command to a variable

Hi, I'm trying to assign the output of a command to a variable and then concat it with another string, however, it keeps overwriting the original string instead of adding on to the end of the string. Contents of test.txt --> This is a test var1="`head -n 1 test.txt`" echo $var1 (This is a... (5 Replies)
Discussion started by: oma04
5 Replies

2. Shell Programming and Scripting

assigning command output to a shell variable

I have the sql file cde.sql with the below contents: abcdefghij abcwhendefothers sdfghj when no one else when others wwhen%others exception when others Now I want to search for the strings containing when others together and ceck whether that does not occur more than once in the... (2 Replies)
Discussion started by: kprattip
2 Replies

3. Shell Programming and Scripting

Assigning output of command to a variable in shell

hi, I want to assign find command result into some temporary variable: jarPath= find /opt/lotus/notes/ -name $jarFile cho "the jar path $jarPath" where jarPath is temporary variable. Can anybody help on this. Thanks in advance ----Sankar (6 Replies)
Discussion started by: sankar reddy
6 Replies

4. Shell Programming and Scripting

Assigning output to a variable

I am new to unix shell scripting. I was trying to convert each lines in a file to upper case. I know how to convert the whole file. But here i have to do line by line. I am getting it in the below mentioned script #!/bin/bash #converting lower to upper in a file #tr "" "" <file1... (3 Replies)
Discussion started by: jpmena
3 Replies

5. Shell Programming and Scripting

Assigning output of a command to variable

When I run time -p <command>, it outputs: real X.XX user X.XX sys X.XXwhere X.XX is seconds. How I can take just that first number output, the seconds of real time, and assign that to a variable? (9 Replies)
Discussion started by: jeriryan87
9 Replies

6. UNIX for Dummies Questions & Answers

assigning (numeric) command output to var tcsh

Hello, I'm trying to assign a numeric value that is returned from one of my programs to a variable in tcsh. I want to do: @ r10 = './my_prog file 35' where ./my_prog file 35 returns a decimal value, but this doesn't work. How do I achieve the desired result? Janet (4 Replies)
Discussion started by: psran
4 Replies

7. Shell Programming and Scripting

Problem with assigning output of grep + awk to a variable

Hi All, I am getting the output for the following command when i run it on the unix console. --------------------------- grep `whoami` /etc/passwd | awk '{print ($1);}' | cut -d ":" -f3 ---------------------------- But i made it into a script and tried to print the variable, its... (5 Replies)
Discussion started by: meheretoknow
5 Replies

8. UNIX for Dummies Questions & Answers

Assigning the output of a command to a variable, where there may be >1 line returned?

Hello I am using unix CLI commands for the Synergy CM software. The command basically searches for a folder ID and returns the names of the projects the folder sits in. The result is assigned to a variable: FIND_USE=`ccm folder -fu -u -f "%name"-"%version" ${FOLDER_ID}` When the command... (6 Replies)
Discussion started by: Glyn_Mo
6 Replies

9. Shell Programming and Scripting

Assigning output from awk to variable

I have a script whose contents are as below result= awk 's=100 END {print s }' echo "The result is" $result The desired output is The result is 100 My script is running without exiting and i am also not getting the desired output. Please help (5 Replies)
Discussion started by: bk_12345
5 Replies

10. Shell Programming and Scripting

Expect - assigning UNIX command output to a variable

Hi, I'm writing a script that connects through ssh (using "expect") and then is supposed to find whether a process on that remote machine is running or not. Here's my code (user, host and password are obviously replaced with real values in actual script): #!/usr/bin/expect set timeout 1... (3 Replies)
Discussion started by: oseri
3 Replies
FINFO_OPEN(3)								 1							     FINFO_OPEN(3)

finfo_open - Create a new fileinfo resource

       Procedural style

SYNOPSIS
resource finfo_open NULL ([int $options = FILEINFO_NONE], [string $magic_file]) DESCRIPTION
Object oriented style (constructor): finfo::__construct NULL ([int $options = FILEINFO_NONE], [string $magic_file]) This function opens a magic database and returns its resource. PARAMETERS
o $options - One or disjunction of more Fileinfo constants. o $magic_file - Name of a magic database file, usually something like /path/to/magic.mime. If not specified, the MAGIC environment variable is used. If the environment variable isn't set, then PHP's bundled magic database will be used. Passing NULL or an empty string will be equivalent to the default value. RETURN VALUES
(Procedural style only) Returns a magic database resource on success or FALSE on failure. NOTES
Warning The expected magic database format changed in PHP 5.3.11 and 5.4.1. Due to this, the internal magic database was upgraded. This mostly effects code where an external magic database is used: reading an older magic file will now fail. Also, some textual repre- sentations of the mime types has changed, for instance for PHP would be "PHP script, ASCII text" instead of "PHP script text" returned. Note Generally, using the bundled magic database (by leaving $magic_file and the MAGIC environment variables unset) is the best course of action unless you specifically need a custom magic database. EXAMPLES
Example #1 Object oriented style <?php $finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension /* get mime-type for a specific file */ $filename = "/usr/local/something.txt"; echo $finfo->file($filename); ?> Example #2 Procedural style <?php $finfo = finfo_open(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension if (!$finfo) { echo "Opening fileinfo database failed"; exit(); } /* get mime-type for a specific file */ $filename = "/usr/local/something.txt"; echo finfo_file($finfo, $filename); /* close connection */ finfo_close($finfo); ?> The above example will output: text/plain; charset=us-ascii SEE ALSO
finfo_close(3). PHP Documentation Group FINFO_OPEN(3)
All times are GMT -4. The time now is 10:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy