The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office here. All UNIX and Linux Newbies Welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
uppercase to lowercase ajit.yadav83 UNIX for Dummies Questions & Answers 4 10-16-2008 11:36 AM
Lowercase to Uppercase ggovotsis AIX 7 10-16-2008 10:07 AM
UPPERCASE to lowercase with no overwriting? lgd923 Shell Programming and Scripting 1 08-21-2008 08:13 AM
How convert lowercase or uppercase Alex20 Shell Programming and Scripting 5 03-07-2005 07:07 AM
uppercase to lowercase webex Shell Programming and Scripting 4 01-03-2002 02:15 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-10-2009
chilli1988 chilli1988 is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 3
Unix: lowercase to uppercase

I just started to learn unix...
and i needed to make a basic script.

i need to

1. read a file (.txt)
2. count the words of EVERY sentece
3. sentences with odd number of words need to be converted into lowercase
sentences with even number of words need to be converted into uppercase

4.the translation needs to be written into a different file

I just can't sepperate the sentences and count the words of every sentance appart.
can someone help me
thx
  #2 (permalink)  
Old 06-10-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
NO homework please
  #3 (permalink)  
Old 06-10-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
We do not do homework for you. This is clearly homework.
1. use a while read record .. do ... done <inputfilename loop. This reads the file line by line.

2. tr will uppercase or lowercase a whole sentence.

3. wc -w will count the words.

Next, you get to show us what you've done with this.
  #4 (permalink)  
Old 06-10-2009
chilli1988 chilli1988 is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 3
I have not test it yet, because im still dowloading opensuse
could this work?

while read line
do

words = wc –w $line // counting the words of current line

If [ $(($words % 2)) –eq 0] Then // see if number of words is even
echo $File1 | tr '[a-z]' '[A-Z]' < $File2 // if even, change all to uppercase and copy to another file

Else
echo $File1 | tr '[A-Z]' '[a-z]' < $File2 // else; odd, change all to lowercase

Fi

Done < File1
  #5 (permalink)  
Old 06-10-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
small changes req...
Code:
while read line ;do 
words = `echo "$line" |wc -w`  // counting the words of current line
##OR###
###words=` echo "$line" |awk '{print NF}'`####

If [ $((words % 2)) –eq "0" ] ; then // see if number of words is even 
echo "$line" | tr '[a-z]' '[A-Z]' >> outputfile.txt // if even, change all to uppercase and copy to another file 
else
echo "$line" | tr '[A-Z]' '[a-z]' >> outputfile.txt // else; odd, change all to lowercase
fi
done < File1
  #6 (permalink)  
Old 06-10-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
That is pretty close. the < $File1 and < $File2 bits need to change direction.
And. What is the difference between > and >> ?
  #7 (permalink)  
Old 06-10-2009
chilli1988 chilli1988 is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 3
so if i would change the < into > it should be right?

> is overwriting the file
>> is adding 'content' to the file...

i think...

so it should be >>file2

edit: ow right... vidyadhar85 just said it... thx

Last edited by chilli1988; 06-10-2009 at 06:52 PM..
Sponsored Links
Reply

Bookmarks

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 01:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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