Hi,
I need some help on scripting.
I am doing a simple echo of lines and words from a file and I also want to echo the number of lines and words to it.
Where can I get this help
A simple script I am using is
for i in `cat hostfile`
do
echo $i
done
And what I would like to do is something like this:
for i in `cat hostfile`
do
for j in ((j=1;j<=1000;j++))
do
echo $i
echo $j
done
Thanks a lot in advance
I might not be clear on what you're asking for but it sounds like you want the output to be something like prefixing each line with it's line number and it's "word" count.
If that's the case something as simple as:
This assumes that you're going to call it with a list of files to process as described. More sophisticated argument handling could handle switches, or could use standard input if $# starts empty. or do other stuff.
One tricky part of this script is that it keeps using the positional argument list as a way to quickly count the "words" in a line ... and restores the argument list after each line. It's only virtue in all this is that it uses no external commands. It's all shell built-ins.
Another trick here is the use of IFS="" just before the read command. Note that this is only setting the IFS for the scope of the read command itself, not affecting the IFS value for the set and other commands. (Without that bit of hackery the read command ends up stripping leading and trailing whitespace and any internal sequences of whitespace are squashed down to single instances of one space (assuming the normal IFS settings).
The awk that might work just as well would be much shorter:
There are likely to be differences in word counts between these due to differences in parsing lines into "words." I know that this will usually differ from the output of the wc command. Obviously you may have to use various sorts of regexp or other manipulations depending on what you mean by "words."
I am running a for loop to execute a command to , say 100 hosts, but I don't know how many I have done so far or how many are left
Will it make any sense?
Newbewie,
I'm sorry to say that you're not making any sense to me. You say you're executing a command on a 100 hundred hosts and then your message talks about wanting to number the lines in a file (does that file contain a list of hostnames?). In your original message it looked like you were trying to say something about counting the current line number and the number of words on that line (or something that would involve printing each line prefixed by *two* numbers.
So, I really don't know what you're trying to do. If you just want something like a count down then you could use something like this:
Where this gives you a prevew of which host is about to be contacted with a summary of how many have been done and how many there were, total, when the process first read the file?
Perhaps investing a bit more effort on posting a clear description of what you're trying to do would help.
Hi,
I have attached an output file which is some kind of database file mapping. It is basically like an allocation mapping of a tablespace and its datafile/s.
The output is generated by the SQL script that I found from 401 Authorization Required
Excerpts of the file are as below:
... (2 Replies)
Hi ,
i have a file wich have 50+ of numbers like :
0.014544106
0.005464263
0.014526045
0.005484374
0.014539412
0.005467600
0.014558349
0.005452185
i would like to display the list from the 6th bit to the end for example
0.005452185 (should become) 2185.
I've tried with ... (4 Replies)
sorry couldnt think of a proper title lol
ok i have the following script it asks the user how many html tags they want. Im not sure how to display 2 tags if the user eneters the want only 2 tags
tags as in <p></p> or <h1></h1>
read -p "How many tags" tags1
if
then
echo "<$tags1>... (3 Replies)
Hey,
I guess I am just to stupid and am not seeing the "wood for the trees", but I am always getting strange errors.
I want to create a mesh with coordinates like:
x y z
3.1 3.0 0.75 0 0 1
3.1 2.9 0.75 0 0 1
3.1 2.8 0.75 0 0 1
3.1 2.7 0.75 0 0 1
3.0 ... (10 Replies)
Hi,
how i can display all the unique number from my random number script below;
#!/usr/bin/perl
use strict;
my @alphanum = ( 'A' .. 'Z', 'a' .. 'z', 0 .. 9);
my $random = join('', map($alphanum,(1..5)));
print "$random\n";
Thank You. (1 Reply)
Hello, I am running Solaris 9 and I need to display the serial number of my machine. How can I do this?
Here is my machine info:
SunOS birch 5.9 Generic_118558-09 sun4u sparc SUNW,Sun-Fire-V240
Thank you,
David (5 Replies)
helo i want to implement the following concept in my project
write a c/c++ algorithm for : accept a number from the user not greater than 6 digits and display the number in words i.e. if the input from the user is 18265 then the output should be Eighteen Thousand Two Hundred Sixty Five. if the... (3 Replies)
I'm on a Unix 5.2 server and I want to be able to see my processes to verify they are active and which processor they are running on.
ps -l will show me the status of process (active/stopped/idle)
but to see which processor the process is assigned to I don't know how.
Manpages show -o... (1 Reply)