[bash]Stripping lines from a list


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [bash]Stripping lines from a list
Prev   Next
# 1  
Old 03-28-2008
[bash]Stripping lines from a list

Hello!

I have a script that is (among other things) doing the following:
Code:
list=/tmp/list1.txt
ncftpls -u <user> -p <password> -x "-l1" server.domain.tld > $list
cat $list | nl
echo "Choose file: "
read file
cat /tmp/list1.txt | nl | grep $file | sed -e "s/$file//g" -e "s/ //g" | column -t > /tmp/list2.txt
cat /tmp/list2.txt

With this, i want to choose a file that is located on a server and download it.
the sed lines was given to me on a guy on another forum who said it should do the trick. And it did, somewhat.
In the directory, i have around 40 files.
if i choose 1 - 9, it gives me a list with several lines like this

Code:
Choose file:
9
2 full_mysql_dump_2008-03-24_0:00.sql.gz full_mysql_dump_2008-03-25_06:00.sql.gz 10 full_mysql_dump_2008-03-25_0:00.sql.gz 18 full_mysql_dump_2008-03-26_0:00.sql.gz 1 full_mysql_dump_2008-03-26_12:00.sql.gz 2 full_mysql_dump_2008-03-28_06:00.sql.gz 30 full_mysql_dump_2008-03-28_0:00.sql.gz 35 full_mysql_dump_2008-03-2_00:00.sql.gz 3

but if i choose a higher number, it gives me this:
Code:
Choose file:
33
full_mysql_dump_2008-03-28_18:00.sql.gz

Just as i want it to do.

In this other script that i am working on, i am using the exact same thing, but this time with another directory on the same remote server, where it is only 2 files. (there will be more files there later).
The result is like the first example.
It doesn't cut away all the other lines that i don't want to have there.

Any of you guys who may know what is wrong, or maybe another solution for my problem?

Last edited by noratx; 03-28-2008 at 10:58 PM.. Reason: correcting typos
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Stripping ret of the lines in a file (sed question)

Hi all, I didn't use SED for 20 years and was never an expert. So my current knowledge is about zero. Please be patient with me. I'm neither a native speaker. I have a huge dictionary file and want the rest of the lines stripped. Everything after (and including) the "/" should be stripped. I... (2 Replies)
Discussion started by: Hinnerk2005
2 Replies

2. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

3. Shell Programming and Scripting

For x in a b c; { list; } (in lieu of do list; done) works (in bash) - why and how?

In this post I came across the cited construct. It works! while ... { list; } does not. man bash does not mention it (or, better, I didn't see it). Any reason for / behind this? Am I missing something? (5 Replies)
Discussion started by: RudiC
5 Replies

4. Shell Programming and Scripting

Removing lines from one list from another list.

Hello, I was wondering if there was an easy way to take lines from a single-column list, and remove them from a second single-column list. For example, I want to remove the contents of list 1 from list 2. How would I do this? Contents of list 1: server1a server2b server3c server4a... (2 Replies)
Discussion started by: LinuxRacr
2 Replies

5. UNIX for Dummies Questions & Answers

Stripping down binaries

Hello, I am the CEO of Grand Tech Corporation. We are launching Linux NT and forgive me, but I do not know how to strip binaries down in Mandriva Linux. Can someone tell me a way to?:b: (2 Replies)
Discussion started by: Linux NT
2 Replies

6. Shell Programming and Scripting

Bash script - stripping away characters that can't be used in filenames

I want to create a temp file which is named based on a search string. The search string may contain spaces or characters that aren't supposed to be used in filenames so I want to strip those out. My thought was to use 'tr' with but the result is the opposite of what I want: $ echo "test... (5 Replies)
Discussion started by: mglenney
5 Replies

7. Shell Programming and Scripting

stripping out non-numeric values in a list

hi all, i'm very new to scripting and have the folllowing issue. I have used a few commands to get a list of numbers, but I need to strip away the non-numeric ones, and then need a total of all values. any ideas? root@unixserver # cat myfile | awk '{print $8}'| sort -rn 1504 1344 896 704... (2 Replies)
Discussion started by: badoshi
2 Replies

8. UNIX for Dummies Questions & Answers

merging 2 lines with awk and stripping first two words

Hey all i am pretty new to awk... here my problem. My input is something like this: type: NSR client; name: pegasus; save set: /, /var, /part, /part/part2, /testpartition, /foo/bar,... (9 Replies)
Discussion started by: bazzed
9 Replies
Login or Register to Ask a Question