Appending output to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending output to file
# 1  
Old 02-10-2014
Appending output to file

Hi,

I want to calculate std dev for a list of files and then print the output appended to an existing file.

I have a few folders within the directory Folder, and I am interested in getting the std dev of values in files named as time.txt. In the last pipe, if I print just the sd value, it works okay, but if I print $0 of the file time_a.txt, the sd value is zero, can someone tell me why.

Code:
cat Folder/num*/time.txt | awk '{print $6}' | awk '{x[NR]=$0; s+=$0} END{a=s/NR; 
   for (i in x){ss += (x[i]-a)^2} sd = sqrt(ss/NR); print sd,$0}' Folder/num1/time_a.txt

num1/time.txt
Code:
a b c d e 12
a b c d e 10

num2/time.txt
Code:
a b c d e 14
a b c d e 10

num1/time_a.txt
Code:
a b c d e 22

Expected output
Code:
a b c d e 22 std_dev


Last edited by Franklin52; 02-10-2014 at 07:22 AM.. Reason: fixed code tags
# 2  
Old 02-10-2014
You cannot both read from stdin and a file in awk. You can use a - placeholder so that awk sees stdin as if it were a file..

Try for example:
Code:
echo hello | awk '{print}' file

vs.
Code:
echo hello | awk '{print}' - file

These 2 Users Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script appending output of sql query

I am writing the following script to create the file v_out.txt. sqlplus -s /nolog << EOF CONNECT scott/tiger@orcl; whenever sqlerror exit sql.sqlcode; set newpage 0; SET PAGESIZE 0; SET ECHO OFF; SET FEEDBACK OFF; SET HEADING OFF; SET VERIFY OFF; SET LINESIZE 100; set tab off; set... (7 Replies)
Discussion started by: itzkashi
7 Replies

2. UNIX for Dummies Questions & Answers

Appending columns at the end of output using awk/sed

Hi , I have the below ouput, =====gopi===== assasassaa adsadsadsdsada asdsadsadasdsa sadasdsadsd =====kannan=== asdasdasd sadasddsaasd adasdd =====hbk=== asasasssa .... .. I want the output like as below, not able paste here correctly. (2 Replies)
Discussion started by: eeegopikannan
2 Replies

3. Shell Programming and Scripting

Appending standard C Time on each line out output

I have a command : nawk 'BEGIN{print srand()}' which gives the amount of seconds between January 1st 1970 00:00:00 (Unix Epoch) and the present time, to the closest second and I would want to append this time stamp every minute in a file which contains the data below which also has one row... (1 Reply)
Discussion started by: thinktank
1 Replies

4. Shell Programming and Scripting

Appending script output to file

Hi guys, I have a script from which I would like its standard output results (upon execution) to be appended to a separate file (.txt format). How can I write such a command into the script for this to occur? I know there should be a >> involved somewhere. Thanks! (5 Replies)
Discussion started by: jjb1989
5 Replies

5. UNIX for Dummies Questions & Answers

Appending sed output to variable

I want to append matched output and cat the results into an variable. but I've been running into problems. sed is printing result on to screen instead of appending the output to $CAPTURE. I'm stumped...how should i fix this? contents of $TEST 10.0.0.1 10.0.0.2 10.0.0.3 10.0.0.4 expected... (5 Replies)
Discussion started by: jazzaddict
5 Replies

6. Shell Programming and Scripting

Appending process output into a file

Hello Friends, I'm trying to save process status of root user sorting by CPU usage. However i couldnt save the continuous, standard outputs into a file. Do you have any idea to do it? prstat -u root -a -s cpu | sed -e '/^$/d;/sleep/d;/Total/d' >> stat.txt >ls -l stat.txt -rw-r--r-- 1... (1 Reply)
Discussion started by: EAGL€
1 Replies

7. UNIX for Dummies Questions & Answers

Appending something to output before being written to a file

Hi, I'm quite stuck with what I thought should've been simple but I just can't seem to do it. Firstly, I have the following done in bourne shell: cat datafile | tr '' '' >> newfile echo "$fullfilepath" >> newfile i want to have the output of that echo put on the same line as the output... (4 Replies)
Discussion started by: Darkst
4 Replies

8. Shell Programming and Scripting

capturing line from script output and appending to a file

Hi all, I did some searching in this forum but can't find anything that matches the issue I'm bumping heads with. On a CentOS4/Postfix (and bash everywhere) mail gateway box I run a command periodically to purge the Postfix queue of messages "From:MAILER-DAEMON". This is the one line'r... (6 Replies)
Discussion started by: wally_welder
6 Replies

9. Shell Programming and Scripting

appending to sed output of one file into the middle of file

hi, i have a file file1 file2 ----------- ----------------- aa bbb ccc 111 1111 1111 ddd eee fff 222 3333 4444 ggg hhh... (5 Replies)
Discussion started by: go4desperado
5 Replies
Login or Register to Ask a Question