Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
my file has the following content: name email === ==== jim jim@hotmail.com susan susan@hotmail.com .... name email === ==== ethan ethan@hotmail.com stephen stephen@hotmail.com ... the output should be: jim jim@hotmail.com ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2007
    Posts
    5

    processing file..please help!!


    my file has the following content:
    name email
    === ====
    jim jim@hotmail.com
    susan susan@hotmail.com
    ....
    name email
    === ====
    ethan ethan@hotmail.com
    stephen stephen@hotmail.com
    ...

    the output should be:

    jim jim@hotmail.com
    susan susan@hotmail.com
    ....
    ethan ethan@hotmail.com
    stephen stephen@hotmail.com

    any idea??

    thanks

  2. #2
    Just Joined!
    Join Date
    Feb 2005
    Location
    India
    Posts
    24
    Hi,
    If u already know what you wanna skip in ur parsing, I don't see what the problem is. U cud:
    1] write a simple routing to read words (read one character at a time till u encouter a white space).
    2] Check if the word is in the Avoid list.
    3] if not forward it to output (whether ur writing it to another file or displaying it on screen).


    Also, if ur allowed to change the format of input, you can have some sort of indicator at the start of lines that you wanna avoid, like if your file can look something like

    #name email
    #==== ====
    jim jim@hotmail.com
    susan susan@hotmail.com

    then it becomes even easier... whenever u encouter a '#' just ignore till '\n'.

    I know I'm asking you to hardcode a lot of things... so if someone has a more generic soln, I'm eagerly waiting for it.

  3. #3
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    you just want to get all the lines with email addresses right?
    eg
    grep "@" file

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Mar 2007
    Posts
    5
    ..the lines after:

    name email
    === ====

    and the above lines occur n time (

  6. #5
    Linux User cyberinstru's Avatar
    Join Date
    Jan 2007
    Location
    India
    Posts
    362
    you just want to get all the lines with email addresses right?
    eg
    grep "@" file
    As ghostdog74 suggested u can do that or try this script out:

    Code:
    #!/bin/bash
    
    STR1="name email"
    STR2="==== ====="
    FILE="./addr.txt"
    FD=6
    
    exec $FD<$FILE
    
    while read -u $FD LINE
    do
    if [ "$LINE" != "$STR1" ]
    then
    if [ "$LINE" != "$STR2" ]
    then
    echo $LINE;
    fi
    fi
    done
    
    exec $FD<&-
    You can simplify multiple IF conditions thr...
    ---------------------------------
    Registered Linux User #440311
    HI2ARUN _AT_ GMAIL _DOT_ COM
    ---------------------------------

  7. #6
    Just Joined!
    Join Date
    Mar 2007
    Posts
    5
    cyberinstru,

    I get the following error on running your script:

    ./s.sh: line 8: exec: 6: not found

    #!/bin/bash

    STR1="name email"
    STR2="==== ====="
    FILE="./addr.txt"
    FD=6 # could u please explain me this line?????

    exec $FD<$FILE # at this line!!!!!!!!!!!!

    while read -u $FD LINE
    do
    if [ "$LINE" != "$STR1" ]
    then
    if [ "$LINE" != "$STR2" ]
    then
    echo $LINE;
    fi
    fi
    done

    exec $FD<&-

  8. #7
    Linux User cyberinstru's Avatar
    Join Date
    Jan 2007
    Location
    India
    Posts
    362
    FD=6 # could u please explain me this line?????
    FD ... any file descriptor other than 0,1 and 2

    Code:
    exec $FD<$FILE # at this line!!!!!!!!!!!!
    This line shud open the file $FILE (addr.txt - whr the email IDs and names are stored).

    You can try this one by doing
    Code:
    exec 6<(filename)
    at the command prompt, then execute the script. It shud work.
    ---------------------------------
    Registered Linux User #440311
    HI2ARUN _AT_ GMAIL _DOT_ COM
    ---------------------------------

  9. #8
    Just Joined!
    Join Date
    Mar 2007
    Posts
    5
    .. I get the error:
    ./s.sh: line 8: exec: 6: not found
    ((

  10. #9
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    awk ' $0 !~ /name email/ && $0 !~ /=== ====/ { print }' file

  11. #10
    Just Joined!
    Join Date
    Mar 2007
    Posts
    5
    ghostdog74,

    I notice that the records ends with ^F (dec 06) , then new line.

    The question is how to tell awk to skip if $0 matches that character ^F??

    Thanks

Page 1 of 2 1 2 LastLast

Posting Permissions

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