If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Unix help needed!!!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-25-03, 07:17
Rho Rho is offline
Registered User
 
Join Date: Oct 2003
Location: Ireland
Posts: 9
Wink Unix help needed!!!

Hi there,
I have a file that contains a list of names. I need to select a certain name and chop it down in size but this name occurs here and there in my list and i need to chop it down without changing where it occurs in the list of names. Confused? Here is an example:

List of names
Mandy1234
Joe
Sean
Jeff
Mandy3467
John
Sarah
Mandy9987
etc....

I need to chop all the Mandy#### down to Mandy without changing the order of the list. I am very new to Unix and i have looked at awk and sed and grep but i can't seem to use them in a way that doesn't change the order of my list.
If anyone can help me i'd really appreciate it!
Ta lots,
Rho
Reply With Quote
  #2 (permalink)  
Old 11-25-03, 09:35
dbabren dbabren is offline
Registered User
 
Join Date: Jul 2003
Location: England
Posts: 152
one way would be to build it into an if statement

eg

cat /dev/null > newfile

for line in `cat file`
do

if [ `grep Mandy $line | wc -l` -ne 0]
then
"Carry out you sed command to alter appearance of mandy" >> newfile
else
cat $line >> newfile
fi

done

Enjoy ..
__________________
Regards
Dbabren
Reply With Quote
  #3 (permalink)  
Old 11-26-03, 08:39
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Sed should do all of this for you...

sed '/^Mandy[0-9]*$/s/[0-9]*$//' yourFile > newFile

This says that if the line begins with 'Mandy' followed by any number of 0-9s, substitute the numeric portion for an empty string.

HTH
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On