LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-10-2011, 07:25 AM   #1
Christos Badogias
LQ Newbie
 
Registered: Nov 2011
Posts: 9

Rep: Reputation: Disabled
script help please!!!!


hello.i have to find all the files which names is sound_x from a directory which call micro!!!the x is a variable and the files names are sound_5,sound_38,sound_101..etc...!!!then i should create a file(name newfile) which should contain the line 5 from the file sound_5,the line 38 from the file sound_38,the line 101 from the file sound_101. The newfile should be classified!for examble the line 5 should be over the line 38 in the new file!!!!
So far i have done only this...
find . -name "sound_*" fprint "temporary_files"
 
Old 11-10-2011, 07:36 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
Quote:
Originally Posted by Christos Badogias View Post
So far i have done only this...
find . -name "sound_*" fprint "temporary_files"
Then best look at your course material, ask your instructor to explain lessons 1 through 10 again or read some basic tutorials as you've shown no knowledge of shell scripting at all in this or your previous thread:

Code:
function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/ 
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq 
http://wooledge.org/mywiki/BashPitfalls"; }
 
2 members found this post helpful.
Old 11-10-2011, 10:32 AM   #3
Christos Badogias
LQ Newbie
 
Registered: Nov 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
Talking

l had read the beginners tutorials and i have done my homework script which contains 9 questions,this is the only one which can not do it,to finish it!so if you have any idea to help me i appreciate more than junge me.
 
0 members found this post helpful.
Old 11-10-2011, 11:06 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,949

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by Christos Badogias View Post
l had read the beginners tutorials and i have done my homework script which contains 9 questions,this is the only one which can not do it,to finish it!so if you have any idea to help me i appreciate more than junge me.
Sorry, but unSpawn gave you a good answer, with good direction.

If you have to write a script, and all you've done is ONE LINE....that's not much effort into it, especially when first two links that he provided tell you explicitly how to use variables, loops, etc. If you don't want people to 'junge' you, post the rest of the script you've written, and where you're stuck.
 
Old 11-10-2011, 11:11 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
Quote:
Originally Posted by Christos Badogias View Post
l had read the beginners tutorials and i have done my homework script which contains 9 questions,
It doesn't show. And backing up what script requirements you've posted only with a 'find' line doesn't show us anything that we can correct to help you with.


Quote:
Originally Posted by Christos Badogias View Post
so if you have any idea to help me i appreciate more than junge me.
It's not a question of judging you or not. The reason why I said that is that asking for handouts doesn't make you learn anything. Here's what you want:
Code:
newfile <( find micro -type f -iname sound_\* -printf "( sed -n \$(basename %p|cut -d '_' -f 2),1p \"%p\" )\n"|/bin/bash )
...but in a way you won't be able to explain to your teacher.
 
1 members found this post helpful.
Old 11-10-2011, 12:24 PM   #6
Christos Badogias
LQ Newbie
 
Registered: Nov 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
haha that is confused.never mind i forgot to use the pipe!!thanks for links!
 
0 members found this post helpful.
Old 11-10-2011, 01:32 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
We help you, you post your script.
That's called reciprocity.
So please do.


Quote:
Originally Posted by Christos Badogias View Post
never mind i forgot to use the pipe!!
Uh. You're a bit young for smoking Crack I think.
 
Old 11-10-2011, 03:47 PM   #8
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,053

Rep: Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881
Sorry to shoot off at something of a tangent, but you are not helping yourself by making your posts easy to read. Here is your first post in this thread re-formatted to include things like capital letters, spaces between sentences and dropped the idiotic excess exclamation marks where it adds nothing at all to the meaning (I have no objection to the use of a single exclamation mark where something exceptional is being pointed out, or to emphasise a point that it easily missed, but to use them just because you are bored with full stops gets wearing very rapidly), so that readability is increased.


Hello.

I have to find all the files which have the name sound_x, from a directory which is called micro. The x is a variable and the files names are sound_5,sound_38,sound_101 (note, you seem to be saying that it is always an integer; that is not the same as saying that it a variable, so be as informative as possible)..etc...

I want to create a file (name newfile) which contains the line 5 from the file sound_5,the line 38 from the file sound_38,the line 101 from the file sound_101. This file, newfile, should be sorted, for example line 5 should be above line 38 in the new file.

So far all I have is this:

Code:
find . -name "sound_*" fprint "temporary_files"
I hope that you agree that this is more readable. While, in any case what you choose do up to you, you need to take into account that if your post is difficult to read, many people will just jump to another post and those who do come to your post may not be as helpful to you if you hadn't made them work to even understand what you are saying. Please do try to act in your own best interests.
 
1 members found this post helpful.
Old 11-11-2011, 10:00 AM   #9
Christos Badogias
LQ Newbie
 
Registered: Nov 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
done:

Quote:
find ./micro -name "sound_*" -fprint "sound_x_files.txt"
cat sound_x_files.txt | cut -d "_" -f 3 > output.txt
cat output.txt | cut -d "." -f 1 > output.txt

sort -n output.txt > sort_output.txt
mkdir new_folder

while read w
sound_x
do
cp ${w} new_folder
done < sound_x_files.txt

while read y
do
sed -n ${y}p ./new_folder/sound_${y}.txt >> new_file.txt
done < sort_output.txt

while read k
do
echo " ${k} "
done < new_file.txt
 
1 members found this post helpful.
Old 11-11-2011, 12:44 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
Hmm.

Code:
cat sound_x_files.txt | cut -d "_" -f 3 > output.txt
cat output.txt | cut -d "." -f 1 > output.txt
This would only print out the literal string "files" and not the "x" position where the number is:
Code:
find ./micro -type f -name "sound_*.txt" | while read ITEM; do
 NUMBER=$(echo ${ITEM}|cut -d "_" -f 2)
 #  ...or make it an array, then select array item 2:
 # NUMBER=(${ITEM//_/ }); NUMBER=${NUMBER[1]}
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash and xterm: how make apps started by and for a script persist when script terminates porphyry5 Linux - General 4 06-15-2011 02:27 PM
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 04:05 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM
ssh - using variables in call to start remote script from local script babag Linux - Networking 2 06-03-2008 05:50 PM


All times are GMT -5. The time now is 08:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration