The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to list files Created in last 2 hrs rsonakiya UNIX for Dummies Questions & Answers 4 03-02-2009 07:25 AM
list the file created before 24 hours using ls command jayaramanit Shell Programming and Scripting 7 09-11-2007 09:46 AM
How to list files with specific created date Draculla Filesystems, Disks and Memory 2 05-04-2007 12:45 AM
List files created between specific date and time jazjit Shell Programming and Scripting 3 04-27-2007 02:19 AM
List Files & Folders created/modified tipsy Shell Programming and Scripting 2 10-24-2006 02:22 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-12-2007
erest8 erest8 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 3
Smile Removing a specific word from a created list

I am working on a script that prompts a user name and creates a list in a username.dat file. Furthermore, I have created a sorted_username.dat file. My question is this: My script uses the word "finished" != finished to break the while loop. How can I avoid having the word "finished" show up in my dat files? Many thanks!
  #2 (permalink)  
Old 10-12-2007
rein rein is offline
Registered User
  
 

Join Date: Dec 2004
Location: Zürich
Posts: 146
Could you post a code sample? This would make it clearer what it exactly is you're trying to achieve.

Otherwise, don't use the word finished as value in your script ....
  #3 (permalink)  
Old 10-13-2007
erest8 erest8 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 3
Smile Here is the code and thank you.

variable=" "
echo $variable > name.dat
while [ "$variable" != "finished" ]
do
echo "Please enter your name (type finished when done)"

read variable
echo $variable >> name.dat
sort < name.dat > sorted_name.dat
echo $variable
done

I am a finance guy trying to learn UNIX. Specifically, I am trying to accomplish a few things here.

1) I want the main screen to show the whole list of names typed in during the session (currently as written the main screen only shows the last name typed in).

2) The way this program is written, the sorted_name.dat file shows a blank line at the top of the list due to the initialization of the variable. I would like to eliminate that first blank line at the top of the list through, perhaps, an adjustment of my code.

3) As you can see, I chose finished as the way to quit the loop. It could be any word that quits the loop. I am trying to find a way to NOT have the != string show up in my lists (on the main screen or on the .dat files.)

Thank you so much.
  #4 (permalink)  
Old 10-13-2007
cali cali is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 1
You can use:
variable=" "
echo $variable > name.dat
while [ "$variable" != "finished" ]
do
echo "Please enter your name (type finished when done)"

read variable
if [ $variable != "finished" ] then
echo $variable >> name.dat
sort < name.dat > sorted_name.dat
fi
echo $variable
done

Good luck.
  #5 (permalink)  
Old 10-13-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,554
while [ 1=1 ]; do printf "Please enter your name: (qQ) to quit: " read choice case $choice in "Q"|"q" ) break;; esac printf "$choice\n" >> name.dat done sort name.dat > sorted_name.dat
Code:
while [ 1=1 ];
do
     printf "Please enter your name: (qQ) to quit: "
     read choice
     case $choice in
     "Q"|"q" ) break;;     
     esac
     printf "$choice\n" >> name.dat
done
sort name.dat > sorted_name.dat
        
-->
Code:
while [ 1=1 ];
do
     printf "Please enter your name: (qQ) to quit: "
     read choice
     case $choice in
     "Q"|"q" ) break;;     
     esac
     printf "$choice\n" >> name.dat
done
sort name.dat > sorted_name.dat
  #6 (permalink)  
Old 10-14-2007
erest8 erest8 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 3
Cali, I tried your script...

Cali,
I appreciate your help. I tried running this script you sent me, but when I run it I get a syntax error at line 12...regarding the fi. Could you please help me a little more and please let me know what exactly the fi means/does? Also, will this script eliminate the blank entry at the top of my .dat files?
Thank you very much.


Quote:
Originally Posted by cali View Post
You can use:
variable=" "
echo $variable > name.dat
while [ "$variable" != "finished" ]
do
echo "Please enter your name (type finished when done)"

read variable
if [ $variable != "finished" ] then
echo $variable >> name.dat
sort < name.dat > sorted_name.dat
fi
echo $variable
done

Good luck.
Closed Thread

Bookmarks

Tags
learn unix

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0