Can we get output on ls | wc -l command on the same line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can we get output on ls | wc -l command on the same line?
# 1  
Old 04-26-2012
Can we get output on ls | wc -l command on the same line?

can we get o/p of
Code:
ls | wc - l

command on the same line.


Code:
[root blg]# ls nc*010412* | wc -l
     23
[root blg]# ls nc*010412* | wc -l
     24
[root blg]# ls nc*050412* | wc -l
     21
[root blg]# ls nc*040412* | wc -l
     23
[root blg]# ls nc*070412* | wc -l
     22

my expectation is grepping specific lines from the file and getting output like this

Code:
010412   23
050412   24
040412   23
070412   22

# 2  
Old 04-26-2012
Code:
dt=010412;echo $dt $(ls nc*$dt*|wc -l)

# 3  
Old 04-26-2012
Bug

try this one

Code:
wc -l cat *

# 4  
Old 04-26-2012
Quote:
Originally Posted by pamu
try this one

Code:
wc -l cat *

will not work for 2 reasons:

1) the requirement is to get the number of files with the pattern and not the number of lines in the files.

2) the first output line will be
Code:
wc: 0653-755 Cannot open cat.

.
# 5  
Old 04-26-2012
dear

text contents are
Code:
^[]0;root blg]# ls nc*010412* | wc -l
     24
^[]0;root blg]# ls nc*010412* | wc -l
     24
^[]0;root blg]# ls nc*010412* | wc -l
     24
^[]0;root blg]# ls nc*010412* | wc -l
     24





error msg is
Code:
dt=010412;echo $dt $(ls nc*$dt*|wc -l) <sagar1.txt
nc*010412* not found
010412 0


Last edited by Scrutinizer; 04-26-2012 at 11:47 AM.. Reason: corrected pasto
# 6  
Old 04-26-2012
i m not clear but if you want to use ls and wc commd with together, maybe try this Smilie
Code:
# echo "ls nc*010412*|wc -l"|awk '{x=$0;gsub(/nc\*|\*\|wc/,"",$2);printf "%s\t",$2;system(x)}'

# 7  
Old 04-26-2012
error msg is like this


Code:
sh: root^G[:  not found.
0
        sh: 24:  not found.
blg]#   sh: ^[]0:  not found.

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

2. Shell Programming and Scripting

How to execute a command on each line of output from another command?

Hello :) new to bash not to programming. I have an on-going need to change the owning group on sets of files and directories from the one they were created with or changed to on update to the one they need to have going forward. find {target_root} -group wrong_group gets me a newline... (4 Replies)
Discussion started by: naftali
4 Replies

3. Shell Programming and Scripting

1 command line gunzip -c get 3 output.

Hi everyone----I have big file like 15G to 20G and took really long time to get the output, cause run 3 steps gunzip -c below to get the ouput. Is there is the way can run 1 command line gunzip -c then get all 3 output (Unzipped Bytes, Records, Record, Length) same time? Please any input for... (5 Replies)
Discussion started by: dotran
5 Replies

4. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

5. Shell Programming and Scripting

How to join output of two command in same line?

Hi I am trying to figureout how to join output of two command in unix in the same line. for e.g. $ankit : df -h | egrep -w /home | awk '{print -n $1 "\t" $5}' ;stat --format=%a /home Output: 0148G /home 775 I want this output as... 0148G /home 775 Please let me know if you... (7 Replies)
Discussion started by: kotak86
7 Replies

6. Shell Programming and Scripting

Bash - Loading a command's output line by line into an array

I have been trying this a lot of different ways and haven't found too much online. Here's what I've got so far: j=0 declare -a first zero=(`cat $tmpfile`) for i in "${zero}" do command $i >> "${first}" ... (4 Replies)
Discussion started by: Azrael
4 Replies

7. Shell Programming and Scripting

reading ps command's output line by line

hi; as a pseudo; while read psLine do myFunc $psLine done < ps i don't want to redirect ps command's to a file. in fact, my problem is "how can i read stdout line by line in bash, sed, awk or any?" thanks, (5 Replies)
Discussion started by: s. murat
5 Replies

8. AIX

ls command output in single line

Hi, Can anyone suggest me how can I display the output of ls command in single line with some delimiter say pipe (|)? I know it can be done by writing a script by using the loops but I wanted to know are there any other single line commands? Thanks for your help Sheshadri (7 Replies)
Discussion started by: arsheshadri
7 Replies

9. UNIX for Dummies Questions & Answers

Command output on ONE line

We want to make a history of errors and append a line to a file each day. To do this we want to display the output of Date and DU (of 1 file) on ONE line. However if i type Date ; DU the output is displayed on two lines. Can Anyone help me please? The output should look like this; ... (1 Reply)
Discussion started by: Robey
1 Replies
Login or Register to Ask a Question

Featured Tech Videos