Results 1 to 10 of 34
I am trying to write a shell script that will take two files and rearrange the names and data below that name to be the same in both files. For ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-11-2005 #1Just Joined!
- Join Date
- Nov 2005
- Posts
- 1
NEED HELP- SHELL SCRIPT PLEASE
I am trying to write a shell script that will take two files and rearrange the names and data below that name to be the same in both files. For instance in one file I have
>ABC
ATGAGGGDG
>DEF
GTACGGATT
And in the other file I have
>DEF
GTACGGATT
>ABC
ATGAGGGDG
Now I want the both files to be in the same order
Can anyone please help me.
Thanks very much.
- 11-11-2005 #2Linux Engineer
- Join Date
- Jan 2005
- Location
- Chicago (USA)
- Posts
- 1,028
Originally Posted by http://www.linuxforums.org/rules.php
- 11-15-2005 #3Just Joined!
- Join Date
- Oct 2005
- Posts
- 23
I just thought that rather than creating an entirely new thread for this, I would use an EXISTING one.
I'm having major difficulties with what I think must be something very simple to do.
I've written a little script whereby a file is created that contains a list of all files present in the current directory. I now though would like to make it so that the number of files in the current directory is displayed on screen.
Could anybody tell me how this is done? I'd be extremely grateful.
It'd just be a simple 1-liner I would have thought, but I don't seem to be able to find it anywhere.. I know I'll need the "echo" command there first, but it;s the actual finding of the number of files that I don't quite know how to do.
Thanks
- 11-15-2005 #4
I must be feeling kind today....since you shouldn't be posting your homework...
Look into the wc -l command as well has how to pipe things, and then post what you come up with, if your having problems with a small part of that we might help you....
- 11-15-2005 #5Just Joined!
- Join Date
- Oct 2005
- Posts
- 23
This is MIGHTY confusing..
So far I've written:
#!/bin/sh
-ls >> Files
I think I understand that what that does. It lists the files present in the current directory and moves them into a file called "Files".
I thought that I would need to follow that up with something like:
echo -ls
Which would actually DISPLAY the list itself...
Is that illogical?
I've read over pipes and see that they're a means of moving data from one place to another, but I don't much see how they can help me..
The only moving of data I'm really doing is moving the list of files into "Files", but that can be done with ">>", can't it?
.
..this'll be the death of me
- 11-15-2005 #6
I'm bored so I'll give you some more help.
Okay withwill redirect the output from the redirect command into a file named File.Code:#!/bin/sh ls >> Files
now you want to know how many files there are.
Firstly look up the usage of the wc command with. Look at about the third option down.Code:man wc
Okay so you have a file called File, what you need to do is "read" this file and then redirect the command (pipe it) so it goes through the wc command and it should give you the number of files if you have used the right options and commands.
- 11-15-2005 #7Just Joined!
- Join Date
- Oct 2005
- Posts
- 23
Oh okay great thanks, I see. So I'm on track so far with the code I'd already written.
I cannot check anything through Linux though as you suggested because I don't actually have access to Linux at all as I do this..
I'm effectively working blind, which is I think perhaps what's making it slightly less easy to get my head around..
Apologies for being a nuisance here..
I think i better take a look on google to see exactly what this "wc" command is.
- 11-15-2005 #8
You can check the manpages online, this is the one for wc http://www.linuxcommand.org/man_pages/wc1.html
btw. you realy should at least install something link cygwin if you want to do shell scripting on a none unix environment.
- 11-15-2005 #9Just Joined!
- Join Date
- Oct 2005
- Posts
- 23
Yeah, you're probably right about that. I'm on a shared computer though
until next week, so i'm pretty stuck for now.
I think I understand now though.
So the wc command is basically to do with counting characters, lines, etc...
Would that mean that this would work? :
#!/bin/sh
-ls >> Files
echo "-l"
?
It would be echoing the number of new lines in Files..
Hm I'm assuming that when you use the -ls command to list files, they list them like this:
file1
file2
file3
file4
file5
Or else this wont work at all :shock:
If when you list things they just list them like this:
File1 File2 File3 File4, there'll only be ONE new line, so it wouldn't work.
Maybe if that's the case I should use the -w command to count the number of WORDS..
Blimey this is tricky.
- 11-15-2005 #10Yes if you redirect from the ls command you'll get them in a nice line like above.
Originally Posted by Scarfinger
Okay this is better, but firstly where is the wc -l command? You'll have to use this, as you have worked out to count the number of lines.Code:#!/bin/sh ls >> Files echo "-l"
So you'll need to count the nember of lines in File <<-- What line of code woud you use for this?
Secondly will File have a lest of each ls added to each other or will it just have the last ls in it? If it's the former the counting of the files becomes more difficult, while if it's the second you'll have to use > not >> to redirect.


Reply With Quote
