piping to script

Apr 10, 2015 at 9:56am
$ ls -la | myScript.sh

How can I using sed do the following?

1. Total number of lines read.
2. Total number of different users (owners).
3. Total number of files with execute permission for the owner.
4. The top 3 largest directory.

I just need some hints.

here is my code for 1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
Read line

while(line)
	
	do

		echo -n "$line"
		count=$((count+1))
		sed 

	done   

echo "Total lines read: $((count-1))"


thanks
Last edited on Apr 10, 2015 at 3:08pm
Apr 10, 2015 at 2:55pm
if you didn't realise it yet, this is a c++ forum. You may have better responses if you use another website.

> exemplary usage of sed
but you don't use `sed' in your snip.

> 1. Total number of lines read.
wc

> 2. Total number of different users (owners).
cut
sort
uniq
wc

> 3. Total number of files with execute permission for the owner.
perhaps you may use `find . -maxdepth 1 -executable'
you can also use `cut --characters=4' and then grep for 'x'

> 4. The top 3 largest directory.
`ls' does not provide the size of directories, you may use `du' for that
Apr 10, 2015 at 3:04pm
thanks, can you tell me pls why I am getting blank if I do this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash

while(read line)
	
	do

		echo "$line"		
		count=$((count+1))
		
		

	done    

echo "Total lines read: $((count-1))"
Apr 10, 2015 at 6:13pm
Because of the meaning of parenthesis. http://www.tldp.org/LDP/abs/html/subshells.html
A command list embedded between parentheses runs as a subshell.
Variables in a subshell are not visible outside the block of code in the subshell.


while read line
Apr 13, 2015 at 2:01pm
thanks
Topic archived. No new replies allowed.