Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

A script question

  • 21-11-2002 3:43pm
    #1
    Registered Users, Registered Users 2 Posts: 14,149 ✭✭✭✭


    Hey guys,

    doing a little shel scripting here and having a couple of little dilemmas.

    I'm trying todo is search for every instance of a pattern in a file (in this case partial names from email addresses). Each instance is placed into a 1D array. Since the search returns the entire line for each instance
    (eg. To: John Doe <john.doe@blah.com>)

    I am then trying to search through each entry in the array for patterns with '@' in them, and then stripping out any '<' or '>' characters if they exist.
    (I incidentally have NO clue how to go about that last bit)

    I'm having problems as sooin as I reach attempting to search each array entry, since grep would appear to only work with files and directories.

    here's the code:
    function release
    {
            uname=$1
            file=$2
            declare -a list[]
            count=0
    
            for a in `grep "$uname" "$file"`
            do
                    list[$count]="$a"
                    count=`expr $count + 1`
            done
    
            echo "Name: $uname"
            echo "File: $file"
           
    
            for((j=0; $j < $count; j++))
            do
                    if [ `grep "@" ${list[$j]}` ]; then
                            echo "${list[$j]}"
                    fi
            done
    
            #blah
            #blah
    }
    

    and here's the current output for this function:

    Name: james
    File: gAEFXj200027062
    grep: To:: No such file or directory
    grep: Systems: No such file or directory
    grep: Solutions: No such file or directory
    grep: <john.doe@blah.com>: No such file or directory
    grep: cc:: No such file or directory
    grep: johnd@blah.com: No such file or directory


    Any ideas?


Comments

  • Registered Users, Registered Users 2 Posts: 14,149 ✭✭✭✭Lemming


    Stupid stupid stupid ...

    just used a filter fior my first problem.

    eg. echo var[n] |grep "@"

    anyway, all I need to do now is figure out how to get rid of the likes of the '<' and '>' tags in an array element

    eg. <john.doe@blah.com>


  • Registered Users, Registered Users 2 Posts: 521 ✭✭✭Ronin


    be lazy and use sed to stript off the offending characters that you don't want.

    Ronin


  • Registered Users, Registered Users 2 Posts: 14,149 ✭✭✭✭Lemming


    Ok,

    I'm using awk to search for certain characters at certain points of a string (in this case the start/end)

    But I can't for the life of me figure out how the f*ck to use awk (or sed for that matter) to get rid of these characters, as opposed to deleting the entire line.

    here's an example I created to try and figure out how awk works:
    #!/bin/sh
    
    declare -a list[]
    counter=5
    
    list[0]="<john.doe@blah.com>"
    list[1]="john.doe@blah2.com"
    list[2]="\"john.doe@blah3.com\""
    list[3]="<john.doe@blah4.com"
    list[4]="john.doe@blah5.com>"
    
    for((i=0; $i < $counter; i++))
    do
            echo ${list[$i]} |awk '/^[<"]|[>"]$/'
    
    done
    
    

    What this does is lists all examples which have any of the listed characters in them. What I'd like to do is show ALL, but strip the listed characters from those that have them at the start and/or end .

    The awk/sed mans just aren't sinking in at the moment :(


  • Registered Users, Registered Users 2 Posts: 1,186 ✭✭✭davej


    Use sed:

    sed 's/targetText/replacementText/'

    eg

    echo \<\"john@microsoft.com\"\> | sed 's/["<>]//g'

    gives

    john@microsoft.com

    davej


Advertisement