Results 1 to 5 of 5

Thread: Creating script with GREP OR ?

  1. #1
    Join Date
    Oct 2009

    Creating script with GREP OR ?

    Hi ,

    I am using Unix operating system and need some suggestion regarding script. From a large file containing text I would like to be able to look for a word , and then extract the word with the next n amount of characters or the next amount of characters untill it hits a certain character (such as a / or a ], but not extract the whole line.

    Any idea and help would be great for me!

  2. #2
    Join Date
    Jan 2008

    Re: Creating script with GREP OR ?

    Hello man !

    You want to create a script or to choose the command line to perform whatever you want to do anything else but i have a good suggestion.You question was very difficult to understand that what exactly you need to do.

    I have a solution and you need not create script,you can issue this command from the terminal .

    $ grep beginword infile | sed -e "s/.*beginword/beginword/g" -e "s/endword.*/endword/g"

  3. #3
    Join Date
    May 2008

    Creating script with GREP OR ?

    I think,you need to use this script to achieve your desire.The script is coded as follows -

    while read line
    if echo "$line"|grep "$word" > /dev/null
    then # if word exists in line
    len=${#line} # length of line
    mypos=$(echo "$line"|awk ' { print index($0, "'"$word"'")} ')
    while [[ $mypos -le $len ]]
    do # stop at the end of the line
    # grab the character
    charpos=$(echo "$line"| cut -c$mypos)
    # get the next char position
    if [[ $charpos = "/" || $charpos == "]" ]]
    then # stop at / or ]
    # build the string
    echo "$str"
    done < myfile

  4. #4
    Join Date
    Apr 2008

    Creating script with GREP ?

    According to me,the grep -E command line would be helpful for you to deal with this type of problem.It's exactly a link to this option as 'egrep' because it's so easier :

    The command can be constructed as follows -

    egrep -o '(match|this|or|this)' file.txt

  5. #5
    Join Date
    Apr 2008

    Variation of Grep command

    This would be the one of the helpful site for you to know more about the grep command and their behavior.

    The page would help you provide different optional arguments can be attached with the grep command and then just find out the proper solution for your self and create the script for your own.

    The long description about the Grep command.

Similar Threads

  1. Bash script for creating a new month and year
    By Kohlmann in forum Software Development
    Replies: 4
    Last Post: 30-08-2010, 10:09 PM
  2. creating a script for a host file
    By mopat in forum Technology & Internet
    Replies: 1
    Last Post: 08-07-2010, 12:44 AM
  3. Creating shell script in ubuntu
    By Elizabeth Allen in forum Operating Systems
    Replies: 5
    Last Post: 24-03-2010, 02:35 PM
  4. Need help creating a SCRIPT file for navigation buttons
    By Rob Dizzle in forum Software Development
    Replies: 4
    Last Post: 19-01-2010, 04:53 PM
  5. Problem After Creating Home Folder with vbs script
    By Susan Bradley in forum Active Directory
    Replies: 3
    Last Post: 18-08-2008, 10:33 PM

Posting Permissions

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