Sponsored Content
Top Forums Shell Programming and Scripting awk/sed string search and replace Post 302528626 by Shell_Life on Tuesday 7th of June 2011 02:17:32 PM
Old 06-07-2011
There are several questions that can be asked and many scenarios that can be created based on your description.

In any event, not to get too complicated, here is one possible solution based exactly on your sample data:
Code:
!/usr/bin/ksh
typeset -i mCount
while read mLine
do
  mCount=$(echo ${mLine} | egrep -c 'tropical forest')
  if [[ ${mCount} -ne 0 ]]; then
    mFlag='Y'
  fi
  if [[ "${mFlag}" = "Y" ]]; then
    if [[ "${mLine}" = "" ]]; then
      mFlag='N'
    else
      mCount=$(echo ${mLine} | egrep -c 'wed')
      if [[ ${mCount} -ne 0 ]]; then
        echo '#'${mLine}
        echo 'on mon tue wed they would eat berries'
        mFlag='N'
        continue
      fi
    fi
  fi
  echo ${mLine}
done < input_file

This User Gave Thanks to Shell_Life For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to replace all occurences of a search string using sed

All, Here is what I am searching for using sed. 1 00640000106798 I want to replace that with the following. 8 0064B0000106798 I can do this easy enough from the command line using sed but I need to put the search string in a file and then execute the sed command within a... (2 Replies)
Discussion started by: mjs3221
2 Replies

2. Shell Programming and Scripting

search and replace with restriction (awk, sed)

Hello, i have a file like that foo A new bar A new bar B new I need to replace 'new' with 'done', but only in lines containing 'bar' AND 'A'. output file should then become foo A new bar A done bar B new Sorry im not able to figure it out, not even shure if i should take sed.... (10 Replies)
Discussion started by: knoxo
10 Replies

3. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

4. Shell Programming and Scripting

How to use SED or AWK to search and replace an exact string

I have a file DS1 DDS DS I want to replace only "DS" to "DSmail.blah.com" in a lot of files. I tried sed 's/DS/DSmail.blah.com' but it changes all the lines . thanks in advance (2 Replies)
Discussion started by: gubbu
2 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

Search and replace is not working by sed or awk

Hi , I have one file and in this file i have one like TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;: i want to replace this line with the following line TEST1... (4 Replies)
Discussion started by: ashissau
4 Replies

7. Shell Programming and Scripting

Another sed/awk search=>replace question

Hello, Need a little bit of help. Basically I need to replace lines in a file which were calculated wrong as it would 12 hours to regenerate the data. I need to calculate values based on other files which I've managed to figure out with grep/cut but now am stuck on how to shove these new... (21 Replies)
Discussion started by: f77coder
21 Replies

8. Shell Programming and Scripting

sed - search and replace whole string which contains dot

Hello. I would like to search exactly "string1.string2.string3" and replace it by "new_string1.new_string2.new_string3" And I would like to search exactly "string2.string3" and replace it by "new_string2.new_string3" And I would not found in the result : "string1.new_string2.new_string3"... (3 Replies)
Discussion started by: jcdole
3 Replies

9. Shell Programming and Scripting

How to search and replace string in column in file with command sed?

how to search and replace string in column in file with command sed or other search "INC0000003.in" and replace column 4 = "W" $ cat file.txt INC0000001.in|20150120|Y|N|N INC0000002.in|20150120|Y|N|N INC0000003.in|20150120|Y|N|N INC0000004.in|20150120|Y|N|Noutput... (4 Replies)
Discussion started by: ppmanja3
4 Replies

10. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWgawk | +--------------------+-----------------+ |Interface Stability | Volatile | +--------------------+-----------------+ NOTES
Source for gawk is available on http://opensolaris.org. Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 02:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy