Outputting Results to Indexed List


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Outputting Results to Indexed List
# 1  
Old 08-28-2014
Outputting Results to Indexed List

I'm looking for some suggestions on a command line utility I am making. I would like to use 'find' to locate some files and index the results so the user can choose the correct results from the list and push that input into an open command. A simple example below:
Code:
/Users/admin/Desktop/misc/Untitled 4.txt
/Users/admin/Desktop/misc/Untitled.txt
/Users/admin/Desktop/output 2.txt
/Users/admin/Desktop/output.txt
/Users/admin/Desktop/testr.txt

My intention is to build an interface that shows the index on each line and the end user can choose the index number, like so:

Code:
[0]/Users/admin/Desktop/misc/Untitled 4.txt
[1]/Users/admin/Desktop/misc/Untitled.txt
[2]/Users/admin/Desktop/output 2.txt
[3]/Users/admin/Desktop/output.txt
[4]/Users/admin/Desktop/testr.txt

Any thoughts?
Thanks!

OSX10.9
# 2  
Old 08-28-2014
Maybe you can find something useful in this example:
Code:
#!/bin/ksh
IAm=${0##*/}
tf="/tmp/$IAm.$$"
trap 'rm -f "$tf"' EXIT
find . -type f > "$tf"
nl "$tf"
printf 'Enter number of file to process or 0 to exit: '
read -r line
if [ "$line" == 0 ] || [ "$line" == "" ]
then	exit 0
fi
if [ "$line" != "${line#*[^0-9]}" ]
then	printf '%s: Response must be numeric.\n' "$IAm" >&2
	exit 1
fi
file=$(sed -n "${line}{p;q;}" < "$tf")
if [ "$file" = "" ]
then	printf '%s: Response out of range.\n' "$IAm" >&2
	exit 2
fi
printf 'Do whatever you want with file: %s\n' "$file"

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 08-29-2014
Would be a perfect candidate for the select (bash/ksh) builtin:
Code:
select CHOICE in $(find ... ); do echo $CHOICE; done

, if available on your system...
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for names in one list in another and print results

Hi All , New to the Bash / Shell programming world and looking for some help I have two files 1: Contains a list of names : eg STEVE BOB CRAIG 2: Contains information with those included names but also others that are not in the list (1 Reply)
Discussion started by: Lonerg550
1 Replies

2. Shell Programming and Scripting

Replace string in a file with some content indexed from another file.

We have two files file 1: (usually small, ~100 lines), each line contains a : separated index, value e.g 2: Apple 1: Banana 5: Pear 7: Orange File 2: (usually large, 10 million lines or more), each line contains a single string value. e.g xyz1 xyz2 xyz3 xyz4 xyz5 xyz6 xyz7 Now... (2 Replies)
Discussion started by: AlokKumbhare
2 Replies

3. Shell Programming and Scripting

Can ctag and cscope support recording search results and displaying the history results ?

Hello , When using vim, can ctag and cscope support recording search results and displaying the history results ? Once I jump to one tag, I can use :tnext to jump to next tag, but how can I display the preview search result? (0 Replies)
Discussion started by: 915086731
0 Replies

4. Shell Programming and Scripting

Multiple indexed conditions with ksh

Dear Unix Experts, I have randomly generated the x, y, and z coordinates of 16 atoms of two species, A and B (8 atoms each) Then I calculated the spacing between all the A atoms labeled d1, B atoms labeled d2 and between A and B atoms labeled d3. I would like to save the x, y, z coordinates to... (1 Reply)
Discussion started by: vahid
1 Replies

5. Shell Programming and Scripting

How to extract data from indexed files (ISAM files) maintained in an unix server.

Hi, Could someone please assist on a quick way of How to extract data from indexed files (ISAM files) maintained in an UNIX(AIX) server.The file data needs to be extracted in flat text file or CSV or excel format . Usually we have programs in microfocus COBOL to extract data, but would like... (2 Replies)
Discussion started by: devina
2 Replies

6. UNIX for Dummies Questions & Answers

getting input, then outputting it

Hi! I am a newbie to Unix. I was writing a little game program for fun when thought of an idea to allow data to be saved. I knew to take all of the Predefined variables and put them into a separate file, then including the file in the program. But I am having trouble making it so that the user... (0 Replies)
Discussion started by: signebedi
0 Replies

7. Shell Programming and Scripting

outputting data in table from grep results

Hi all. I'm a real unix newbie and looking for some help on a shell scripting problem. I'm going the longest ways around everything but I'm getting there. My next problem however has me stumped. I have set up a program that takes inputs from a user for a particular month and year (and stores them... (2 Replies)
Discussion started by: Chillspark
2 Replies

8. Shell Programming and Scripting

filtering list results

I created a large file list using: find . -type f -mtime +540 > test2.txt ..which searched recursively down the directory tree searching for any file older than 540 days. I would like to filter the results removing the directory name and the "/" character, resulting in only a list of the... (3 Replies)
Discussion started by: fxvisions
3 Replies

9. UNIX for Dummies Questions & Answers

List grep results

Hi I need to search for matching strings in a database and I want to print out all files that matches in "detail", which means that I want the output to contain datum of last saving. I only get the grep function tp print the actual file names which is not enough since the database is to large... (14 Replies)
Discussion started by: slire
14 Replies

10. Programming

indexed sequential access in c files

hi, I want to implement indexed sequential access method in my flat file, Any idea other than INFORMIX C-ISAM library, because it is not free ware, Any Freeware available? (0 Replies)
Discussion started by: vrkiruba
0 Replies
Login or Register to Ask a Question