To store output of ls command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To store output of ls command
# 1  
Old 06-02-2010
To store output of ls command

Hi,

I need to pass a run time input to unix script which tracks the list of files in the directory under certain pattern. The files which are matched to the given pattern then need to be stored in the array. Requesint you all to please suggest me the solution.

I gave the below command in the sh file and when i tried to execute i got only the last entry in the filelist. pls suggest me the possible solution.

purpose of storing these file name in the array:
i have a file with list of strings to be searched in above retrived files.

Code:
ls scr* >> filelist

# 2  
Old 06-02-2010
Code:
ls
dead.letter      err_1705101841.txt
error1.file        err_1705101842.txt
practice_a       err_1805101940.log
pyramid.sh       err_1805101942.log
pyramid1.sh     pyramid2.sh           

ls err* >> ls_store.sh

cat ls_store.sh

It works fine..

Last edited by Franklin52; 06-02-2010 at 03:15 AM.. Reason: Correcting code tags
# 3  
Old 06-02-2010
Hi,
Please try to check by passing input paramter at run time.
Thanks
# 4  
Old 06-02-2010
Assuming filenames don't contain any spaces:
Code:
ARRAY=($(ls err* | tr '\n' ' '))

# 5  
Old 06-02-2010
Hi,

Pasted the code for your reference.

Code:
$ cat run.sh
echo $1
ARRAY=($(ls $1 | tr '\n' ' '))

When i tried to execute,

Code:
$ . ./run.sh scr*

I got the below response only.
Code:
script1.sh

When i tried to execute the cmd directly, i got below update.
Code:
$ ls scr*
script1.sh  script2.sh  script3.sh

Please correct and update, why script1.sh file was alone printed when we pass runtime parameter as scr*

Thanks in advance
# 6  
Old 06-02-2010
Code:
#!/usr/bin/ksh

ls

will nt this works.?
u get all ur file displayed

when u do ls scr* (if their is a file in ur directory that will get displayed)

Last edited by Franklin52; 06-02-2010 at 05:02 AM.. Reason: Correcting code tags
# 7  
Old 06-02-2010
Hi ..
I need to store the files which are matched to my input pattern. I don'tt want to store all files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python - store output of command to a variable

I am trying to store output of python command in variable. Could you please help how I can do that ? For example I am executing the following command - "CentOS" in server_desc The output would be True or False I would like to store the output in a variable say outPut and use condition... (4 Replies)
Discussion started by: atanubanerji
4 Replies

2. Shell Programming and Scripting

ksh : need to store the output of a awk command to a array

I have awk command : awk -F ' ' '{ print $NF }' log filename And it gives the output as below: 06:00:00 parameters: SDS (2) no no no no doc=4000000000). information: (6 Replies)
Discussion started by: ramprabhum
6 Replies

3. Shell Programming and Scripting

how to store output to a variable

I need some help: 1) I have a out put from a shell script, the out put looks like this: Attempting privilege escalation using sudo ... List backups for CLTST: Start date Status Ret. Class Label -------------------- ------------ ------------ ... (2 Replies)
Discussion started by: samk
2 Replies

4. Shell Programming and Scripting

How to store output of command to an array

Hello Guys, I am trying to store output of command to an array and then want to print, but it showing an error that "bad substitution". I am not getting why it's happening. Can anyone help me? #!/usr/bin/sh hr=0 min=0 i=1 last $1 | grep -w `date "+%b"` | grep -v '\(0:.*\)' | grep -vw sshd... (8 Replies)
Discussion started by: kasparov
8 Replies

5. Shell Programming and Scripting

store sqlplus output in variable

hi how can i store sqlplus output to a variable in sh script (not bash) Thanks MM (1 Reply)
Discussion started by: murtymvvs
1 Replies

6. Shell Programming and Scripting

store the output of "find" command in a variable?

I intend to find the path/full location of a file(filename given by user thru "read filenme") using "find" or any other command and then store it's output in a variable for some other processing. But struggling to put all things together (i.e finding the fully qualified location of that file and... (4 Replies)
Discussion started by: punitpa
4 Replies

7. UNIX for Dummies Questions & Answers

trouble using read to store values in variables from command output

I know there are caveats about using read in pipelines because read is treated by a subshell. I know this but I can't think of any way to accomplish this regardless, I'm still a rookie. I hope somebody will be able to interpret what it is that I'm trying to accomplish and correct me. ... (2 Replies)
Discussion started by: ProGrammar
2 Replies

8. Shell Programming and Scripting

To store the output in a variable

Hi, I am getting the following error while executing the script. Please can someone throw some light where is the problem. Many thanks. ./check: temp: not found The directory related to SEP instance 4 does not exist. The script is as follows. SEP_APP="/scp/sepx/app... (2 Replies)
Discussion started by: Sudhakar333
2 Replies

9. Shell Programming and Scripting

Store output and Echo

I will admit I am a newbie but I am trying to write some simple scripts Situation: I have a list of IP Addresses that I want to once or 2 times a day store the average ping response time in a database (mysql) I am part way there but not all the way there I have the following cat ./slow... (2 Replies)
Discussion started by: meyerder
2 Replies

10. Shell Programming and Scripting

store output to a file and read from it

Hello all, I need to run snoop command for a period of time (a day) and extract remote host column from it to find out who is accessing my server. When I run the following on the command line it works snoop -port 22 | awk '{print $3}' but when I do snoop -port 22 | awk '{print $3}' | while... (2 Replies)
Discussion started by: afadaghi
2 Replies
Login or Register to Ask a Question