Removing a specific word from a created list


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Removing a specific word from a created list
# 1  
Old 10-12-2007
Bug 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  
Old 10-12-2007
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  
Old 10-13-2007
Bug 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  
Old 10-13-2007
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  
Old 10-13-2007
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  
Old 10-14-2007
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
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Files created on specific time

Hello Gurus, I am facing one issue to get a file for a specific time. There are about 300 files created between 6.30 pm to 7.15 pm everyday. Now I wanted only the file which is created on 6.45pm. No other files required. I have used "find" command to get the files, but not getting the expected... (3 Replies)
Discussion started by: pokhraj_d
3 Replies

2. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

3. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

4. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

5. Shell Programming and Scripting

Fetch entries in front of specific word till next word

Hi all I have following file which I have to edit for research purpose file:///tmp/moz-screenshot.png body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: &quot;Liberation Sans&quot;; font-size: x-small; } Drug: KRP-104 QD Drug: Placebo Drug: Metformin|Drug:... (15 Replies)
Discussion started by: Priyanka Chopra
15 Replies

6. Shell Programming and Scripting

bash script removing files except last one created

Hello there, can anyone please help to write a bash script that can achieve the following: 1) list files that contain a certain string in order of their creation date. Ideally the script should ask me to type in the string by hand. 2) use that list and remove all except the last one created... (2 Replies)
Discussion started by: kjartan
2 Replies

7. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

8. Shell Programming and Scripting

How to replace a specific word in specific column?

Hi My orginal file is like (100s of lines) id host ip location remarks 1 host1 ip1 - xxx 2 host2 ip2 - xxx 3 host3 ip3 - xxx -- -- 9 host9 ip9 - xxx I have a ref file like host1 location1 host2 location2 host3 location3 -- --... (6 Replies)
Discussion started by: ./hari.sh
6 Replies

9. Filesystems, Disks and Memory

How to list files with specific created date

Hi, Would like to ask, which command is used to list all the files for specific date (says 1st May) and its size, for all files (including its subdirectory), in a mounted NFS disk to HP-UX. I would like to check for the total files came into my disk on 1st May. Very much appreciating your... (2 Replies)
Discussion started by: Draculla
2 Replies

10. Shell Programming and Scripting

List files created between specific date and time

Hi I need to write a script to list files in a directory created within specific date and time for eg list files created between Apr 25 2007 11:00 to Apr 26 2007 18:00. and then i have to count them Any suggestions pls ? (3 Replies)
Discussion started by: jazjit
3 Replies
Login or Register to Ask a Question