Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Location
    Ireland
    Posts
    9

    Wink Unanswered: 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

  2. #2
    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

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •