Using ls output for other process

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using ls output for other process
# 1  
Old 02-19-2008
Using ls output for other process


Just to set the tone: I am a complete UNIX noob (i guess you see that excuse popping up frequently here but anyhow)
Now here's my bloody simple problem which needs to be quite urgently resolved: I have a number of files in a directory, for which the ones, relevant for executing a subsequent action, can be easily gathered using an ls -1 | cut -c1-5 command. What I want to do know is plug in each filename resulting out of this ls command into another command. Hence, I need to temporarily store each name into a variable, execute the other command by using that variable and then move on to the next one untill the list is finished.

PS: if someone knows a fool proof unix guide on the web which enables even an amoebe to learn unix, feel free to post the link.

# 2  
Old 02-19-2008
for i in `ls`; do echo $i;done

# 3  
Old 02-20-2008
Originally Posted by ilan
for i in `ls`; do echo $i;done

This comes close but not yet perfect. Now "i" is filled with just the regular filename, but I need to have that string made shorter with the cut command.
# 4  
Old 02-20-2008
for i in `ls | cut -c1-5 `; do echo $i; done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Process output in different layout

I was looking for samething more compact than this: $: a=`ls` $: declare -i num=0 $: for x in $a; do num=$num+1; echo "$num ..... $x"; echo "$num $x">fl_tmp; done And jump in my mind to use parallel but look at the performance: $: a=`ls` $: time for n in {1..10}; do parallel... (3 Replies)
Discussion started by: flaviofachin
3 Replies

2. Shell Programming and Scripting

Bash process output analysis

Looking to create a script to listen to each output from a task while it is running and launch a function if a specific error message is found at any point and if not to continue uninterrupted. #!/bin/bash read checker <<< $(reaver -i mon0 -b 'target bssid' -vv) if ; then function elif... (1 Reply)
Discussion started by: 3therk1ll
1 Replies

3. UNIX for Dummies Questions & Answers

Seeing output of background process

I'm pretty sure I had the answer to this months ago and have misplaced it. Needless to say I will bookmark it this time. I have a background process that's been running way longer than usual. It doesn't output anything to a file, so I can't 'tail -f' it. Is there a command that will enable me to... (2 Replies)
Discussion started by: dheian
2 Replies

4. Shell Programming and Scripting

Appending process output into a file

Hello Friends, I'm trying to save process status of root user sorting by CPU usage. However i couldnt save the continuous, standard outputs into a file. Do you have any idea to do it? prstat -u root -a -s cpu | sed -e '/^$/d;/sleep/d;/Total/d' >> stat.txt >ls -l stat.txt -rw-r--r-- 1... (1 Reply)
Discussion started by: EAGL€
1 Replies

5. Programming

read input-process-output

Can you help me ? I want to write a program ,which can open a input file (input.txt) and run as child process ,then write to output file (output.txt)....... char inFile="input.txt"; char outFile="output.txt"; int main(int argc, char **argv) { pid_t pid=1; int no=0; // no. of... (5 Replies)
Discussion started by: cupid1575
5 Replies

6. Shell Programming and Scripting

Write process output to a file

When I run <ls -l> to get a list of all the files, I want the displayed result to be written to a text file. Is there a way to do that? (1 Reply)
Discussion started by: kn.naresh
1 Replies

7. Shell Programming and Scripting

problem parsing process-output

HI all! I have a problem parsing the output of another process. The output is like this (C): printf("\rCheck exist: %d/%d",idx,pBF->NBits()); The aim of the script I'm coding is to save in a separate file the last output line of first process. This is the script now (Shell script): ... (3 Replies)
Discussion started by: victorin
3 Replies

8. Shell Programming and Scripting

Can ps just output the process name?

I'm trying to get the ps command to just output the name of the processes currently running, but I can't figure out a way to do it. I'm using OSX, so some UNIX features are crippled. Is there any way for me to do this? Thanks, Black Leopard (4 Replies)
Discussion started by: blckleprd
4 Replies

9. UNIX for Dummies Questions & Answers

Opening output file while still in process

Dear guru, Say I have a long process that is executed in this way: $ nohup perl > output.txt & Now if I want to view the output file with vi, while process still running: $ vi output.txt Will it kill the process? (seems to me it does). If so how can view the file without... (4 Replies)
Discussion started by: monkfan
4 Replies

10. UNIX for Advanced & Expert Users

Retreive process output

Hi, I had a process that was producing a standard output (no log of it eing produced), unfortunalty the xterm it was running in died and I lost the output. I have logged back in and can see that the process didn't die. How can I bring this process to the foreground so that I can see the output?... (2 Replies)
Discussion started by: nhatch
2 Replies
Login or Register to Ask a Question