I have a script that is (among other things) doing the following:
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
but if i choose a higher number, it gives me this:
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
No offense, but I'm sorry, that's a really hideous script. I guess the problem is that you are grepping without anchoring the grep, so it prints any line which contains the indicated number anywhere.
Here is a refactored version, with the following changes.
* cat file | command is known as "Useless Use of Cat". Changed those.
* grep | sed similarly refactored to use only sed, anchored at the beginning
* You use $file and /tmp/file1.txt interchangeably. Standardize on the former.
* Since you are not using file1 without the nl, doing the nl once and saving it in the file.
* Remove the temp file when done.
* The second temp file is apparently unnecessary, unless you are only showing part of the script.
No offence taken. =)
I'm pretty much a newbie, so writing hideous scripts is what you do at the beginning (i think).
As you mentioned, i was only showing a part of the total script.
Here is the whole funcion in the script (the rest is working as it should).
Also, the script that i wrote here in the beginning, is a snippet from a testing script that i used. Before i make major changes in the original script (that worked before i started to change it from backing up my MySQL database to backing up my home directory), i make minor testing scripts just to see if the changes works as i want the to. Because of that, some names (like the list names) may not be the same.
The paths and programs are entered in the beginning of the total script (like ncftpls=/usr/local/bin/ncftpls), in case you would wonder why i use $ncftpls and such.
No offence taken. =)
I'm pretty much a newbie, so writing hideous scripts is what you do at the beginning (i think).
Yeah, sorry about the tone there.
The rest of the script really looks quite reasonable, apart from the inexplicable urge to spoon-feed nl with cat, as if it couldn't read the file itself. Ditto for awk etc.
Another minor nit I have is about how you capture stuff with backticks only to echo back the output to the user. Just take out the backticks and let the output go to standard output if you want the user to see it. (Echoing also has some subtle side effects, which you might or might not want. You avoid a lot of quoting quandaries if you just don't do that.)
Quote:
The paths and programs are entered in the beginning of the total script (like ncftpls=/usr/local/bin/ncftpls), in case you would wonder why i use $ncftpls and such.
Frankly, I think that's a dubious practice -- just make sure your PATH is set up correctly, and use the actual program names without putting them in variables. That's easier to port to a different system where the paths are different, too.
All in all, not too hideous at all. Hope this helps.
Last edited by era; 03-29-2008 at 09:42 AM..
Reason: Remark on echo `output from backticks` too
I got a problem with the code you canged.
To test it before changing it in my script, i created a new script with the code, just to test it.
-b for pr does not exist in my version of pr, i tryed without it, but since i don't know what it does, i don't know if it was better or not (it continued even though the -b option did not exist).
When i chhose the file, it just stops and nothing happends.
I also added list2 and a cat of the list, just so i can see what happends, but nothing is really happening.
Last edited by noratx; 03-31-2008 at 12:12 PM..
Reason: spelling corrections. (pt instead of pr)
Now a new problem has appeared.
When i do
the result is:
And this is already what is in list1.txt.
I tried to change it to this:
and then i get this:
[CODE]
home.tar.bz2
2 itsak.se.homes.2008-03-28_0-30.tar.gz
3 itsak.se.homes.2008-04-0_0-30.tar.gz
[/CODE/
This is allmost what i want, only that the rest:
2 itsak.se.homes.2008-03-28_0-30.tar.gz
3 itsak.se.homes.2008-04-0_0-30.tar.gz
should be removed from the file as well.
Also, when i do "sed "s/1//g" "/tmp/list1.txt" | column -t"
it also removes the numbers from the dates, which is not good.
If the date in the file is removed, then the script won't be able to download the file.
The exact filenames in this example should be:
"itsak.se.homes.2008-03-28_01-30.tar.gz"
and
"itsak.se.homes.2008-04-01_01-30.tar.gz".
Sorry if i behave like a total newbe and asks many questions, but i am trying to learn. (And to learn even better, i just bought a "sed & awk reference book") =)
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)
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)
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)
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)
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)
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)
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)
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)