Sponsored Content
Top Forums Shell Programming and Scripting create outputs from other command outputs Post 302437171 by rajsharma on Wednesday 14th of July 2010 07:40:29 AM
Old 07-14-2010
Bug create outputs from other command outputs

hi friends,

The code:

Code:
i=1
while [ i -le 50 ] 
do
filename=`/usr/bin/ls -l| awk '{ print $9}'`
echo $filename>>summary.csv
#Gives the name of the file stored at column 9
count=`wc -l $filename | awk '{print $1}'`
echo $count>>summary.csv
#Gives just the count of lines of file "filename"
i=`expr $i + 1`
done


It gives the output like:
Code:
filename1.txt#filename
123#count
filename2.txt
234
filename3.txt
567
...
...


But i want the output as
Code:
filename1.txt 123
filename2.txt 234
filename3.txt 567

I want to see the output as .csv file, so the columns shud be separated by comma(,).


I think I have to use awk, but dont knw how to use it to get the desired result.



Any help is appreciated.
Best Regards,
Raj

Last edited by Scott; 07-14-2010 at 09:17 AM.. Reason: Code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

compare 2 outputs

Hello, I have a shell script that is used as follows: ./script -s <Oracle_server_name> the script returns several lines in this format: parameter name required value Current Value comments --------------- ------------- -------------- --------- My objective now is to compare 2... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

2. Shell Programming and Scripting

recording command outputs in background

For example: % ls /store > list.txt % less list.txt % 1.txt % 2.txt I want to execute 'ls' in verbose and store the result in background to 'list.txt' so i dont have to execute another command just to view the contents of the 'list.txt' % ls /store > list.txt % 1.txt % 2.txt %... (2 Replies)
Discussion started by: jehrome_rando
2 Replies

3. Shell Programming and Scripting

Trouble with tee command to capture script outputs

function GetInput { print -n "Input" read input export INPUT=$input } export COMMAND="GetInput" $COMMAND echo "$INPUT" $COMMAND | tee -a Log.log echo "$INPUT" The first one without "tee" works fine. echo "$INPUT" displays the values I type in for input. The second... (5 Replies)
Discussion started by: muthubharadwaj
5 Replies

4. Shell Programming and Scripting

Assigning variable from command outputs to shell

First, this is bash (3.2.17), on a Mac, 10.5.7. What I'm trying to do is look at a list of users, and check to see if each exists. If they do, do some more stuff, if they don't, drop them into an error file. So, my user list is: foo - exists bar - does not exist blah - does not exist ... (2 Replies)
Discussion started by: staze
2 Replies

5. Shell Programming and Scripting

Operating on each of the individual outputs of a command

ps -e -o pcpu,pid,cmd --sort pcpu | sed '/^ 0.0 /d'|awk '{print $2}'|grep -v PID Gives the output: 4482 4023 5912 I want to operate on each pid in the output. How to do so. (2 Replies)
Discussion started by: proactiveaditya
2 Replies

6. Shell Programming and Scripting

How to store multiple outputs from an awk command?

x=`echo $line | awk -F "|" '{print $1;print NR}'` How will I get the 2 return values ($1 and NR) from awk to variables? (4 Replies)
Discussion started by: tene
4 Replies

7. Shell Programming and Scripting

Create tab-delimited file of outputs - Perl

Title is very broad, but here's an outline of what I have done so far: - I have multiple subdirectories containing multiple *.fna files of DNA sequences - I've been able to traverse these subdirectories and create a tab-delimited text file (i.e. the association file) that shows the contents of... (1 Reply)
Discussion started by: shwang3
1 Replies

8. Solaris

Reboot solaris box(What are all the command outputs)

Hi What are all the command outputs we have to note and keep it for safe before rebooting or shutting down a solaris box (5 Replies)
Discussion started by: newtoaixos
5 Replies

9. Shell Programming and Scripting

suppress some grep outputs

Hello Friends, Im working on Ksh (it is not my will :) ) I would like to get rid off the outputs lines which includes "can't open" .. i guess it must be an easy thing but could not find any usefull thing, ls -l *credit* | xargs grep -i "*data*" 22:set conv(DATA) B16 22:proc... (3 Replies)
Discussion started by: EAGL€
3 Replies

10. Shell Programming and Scripting

Time outputs of wget command

Hello friends, I've been working on a solaris server, I need to test responses of a web service using WGET command, if the response is successful, how quick it is etc. I have scirpt like this, I modified it, i try to redirect the output of time command to total.txt but i couldn't manage, i... (4 Replies)
Discussion started by: EAGL€
4 Replies
FWRITE(3)								 1								 FWRITE(3)

fwrite - Binary-safe file write

SYNOPSIS
int fwrite (resource $handle, string $string, [int $length]) DESCRIPTION
fwrite(3) writes the contents of $string to the file stream pointed to by $handle. PARAMETERS
o $handle -A file system pointer resource that is typically created using fopen(3). o $string - The string that is to be written. o $length - If the $length argument is given, writing will stop after $length bytes have been written or the end of $string is reached, whichever comes first. Note that if the $length argument is given, then the magic_quotes_runtime configuration option will be ignored and no slashes will be stripped from $string. RETURN VALUES
fwrite(3) returns the number of bytes written, or FALSE on error. NOTES
Note Writing to a network stream may end before the whole string is written. Return value of fwrite(3) may be checked: <?php function fwrite_stream($fp, $string) { for ($written = 0; $written < strlen($string); $written += $fwrite) { $fwrite = fwrite($fp, substr($string, $written)); if ($fwrite === false) { return $written; } } return $written; } ?> Note On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen(3) mode parameter. Note If $handle was fopen(3)ed in append mode, fwrite(3)s are atomic (unless the size of $string exceeds the filesystem's block size, on some platforms, and as long as the file is on a local filesystem). That is, there is no need to flock(3) a resource before calling fwrite(3); all of the data will be written without interruption. Note If writing twice to the file pointer, then the data will be appended to the end of the file content: <?php $fp = fopen('data.txt', 'w'); fwrite($fp, '1'); fwrite($fp, '23'); fclose($fp); // the content of 'data.txt' is now 123 and not 23! ?> EXAMPLES
Example #1 A simple fwrite(3) example <?php $filename = 'test.txt'; $somecontent = "Add this to the file "; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> SEE ALSO
fread(3), fopen(3), fsockopen(3), popen(3), file_get_contents(3). PHP Documentation Group FWRITE(3)
All times are GMT -4. The time now is 04:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy