Sponsored Content
Top Forums Shell Programming and Scripting For cycle and formatting stdout Post 302949318 by Higgo on Thursday 9th of July 2015 08:54:51 AM
Old 07-09-2015
For cycle and formatting stdout

Dear all,

I want to create a table using a shell script. Hope someone can help.

I created a variable that contains the path for different files.
For all the files I want to do calculations and print it to stdout (or file) as a table.

I tried this code:
Code:
paths=`cat $tabdelim_file | awk '{print $2}' 
names=`cat $tabdelim_file | awk '{print $1}' 

echo -e "header1\theader2\theader3\theader4\theader5"

for i in $path
do
wc -l $i | awk '{print $1}'
awk '{print $3-$2}' $i | awk '{sum+=$1} END {print sum, sum/NR, (sum/2844551878)*100}'
# To header5 I want to print the name for the $i-th tag from $names - dont know how to do it
done

However the output is shifted like:
Code:
header1\theader2\theader3\theader4\theader5
cmd1_out for first element $i
cmd2_out (generates 3 values for header2-4) for first element $i
cmd1_out for second element $i
cmd2_out (generates 3 values for header2-4) for second element $i
etc

How can I create a desired output?
Code:
header1\theader2\theader3\theader4\theader5
cmd1_out\tcmd2_out1\tcmd2_out2\tcmd2_out3\tcmd3_out1\t
cmd1_out\tcmd2_out1\tcmd2_out2\tcmd2_out3\tcmd3_out1\t

Thank you for the answer,

Regards,
Laszlo
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell cycle

Hello I got a cycle in the script which open another scripts. if then action fi Scripts action will be running 2 times at the same time. Inside of action() is insert into the table. But what I want is that only first script can do insert into table. So how to do... (2 Replies)
Discussion started by: mape
2 Replies

2. Shell Programming and Scripting

For cycle

Hello, I have files in a dir. I what to create a FOR cycle that will do this FOR <condition> do file=`ls <directory> | tail -1` echo $file mv -f $file <another dir> done What I want to now is what should I put in the <condition>. The condition I want is that the FOR will execute... (3 Replies)
Discussion started by: nagomes
3 Replies

3. Shell Programming and Scripting

wildcard in a if cycle

hello everybody, I need help on putting a wildcard match inside an if condition (I'm using korn shell): if ] then echo ' ' echo ''$MYSEL' is not a correct option' echo ' ' else ..... i tried also #if -ne "``" and a lot of combinations of `"' but I didn't find the... (2 Replies)
Discussion started by: elionba82
2 Replies

4. Programming

clock cycle count

Hello everybody! Is there a way to count the clock cycles (that a program took to finish) in C? thanx:o (5 Replies)
Discussion started by: nicos
5 Replies

5. Shell Programming and Scripting

for cycle

Hello, I have a question: is there a way to have a "for" cycle done a certain number of times. For example in c++ I can do this: for (i=o;i<10;i++) and the cycle will be repeated 10 times. in UNIX for example I do this: for i in `cat /etc/host` do done and the cycle will be repeated... (6 Replies)
Discussion started by: jcpetela
6 Replies

6. Shell Programming and Scripting

for cycle question

i have a question how to modify below script to generate the expect result below : test.sh #!/bin/bash for ((i=0; i < 25; i++)) do echo $1$i done current result: test.sh 20090101 200901010 200901011 200901012 200901013 200901014 200901015 200901016 200901017 200901018 (2 Replies)
Discussion started by: bleach8578
2 Replies

7. Shell Programming and Scripting

Cycle for with for-then-else

Hi, i would like to insert a if-then-else function in to cycle for -------------- cat test -------------- # cat test ALFA BETA GAMMA ----------------------- This is my script: #!/bin/bash for i in $(cat test); if ; then echo "ok" else (5 Replies)
Discussion started by: elilmal
5 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWgawk | +--------------------+-----------------+ |Interface Stability | Volatile | +--------------------+-----------------+ NOTES
Source for gawk is available on http://opensolaris.org. Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 10:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy