Sponsored Content
Top Forums Shell Programming and Scripting Find string1, when true find string2 in reverse direction Post 303022529 by baris35 on Sunday 2nd of September 2018 12:37:30 PM
Old 09-02-2018
Find string1, when true find string2 in reverse direction

Hello,

This is a bit complicated for me.
My scenario in MyFile:

Search string1,
When string1 is found, grep the line containing string1, go back over that line in upward direction and grep the first line containing string2.

Here is an example:

MyFile

Code:
His email address alfredo@alfredo.ru
test1
test2
test3
testtt 11223344
test4
test5
His email address daniel@alfredo.ru
kkkk
ddd
ggg
www
qqq
testtt 55667788
His email address lucas@alfredo.ru
aaa
bbb
ccc
ddedd
eeeeeeee
ffffff

string1: testtt
string2: @

Expected output:
Code:
His email address alfredo@alfredo.ru
test 11223344
His email address daniel@alfredo.ru
test 55667788

Thanks in advance
Boris
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

command find returned bash: /usr/bin/find: Argument list too long

Hello, I create a file touch 1201093003 fichcomp and inside a repertory (which hava a lot of files) I want to list all files created before this file : find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long but i make a filter all... (1 Reply)
Discussion started by: yacsil
1 Replies

2. UNIX for Dummies Questions & Answers

Replacing string1 with string2 in many files

I have 70 files and want to replace string1 with string2. How can i do that?. Thanks (4 Replies)
Discussion started by: shashikandi
4 Replies

3. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

4. Shell Programming and Scripting

Remove lines before string1 and after string2

Hello All... I have a text file (.ics) which I need to read into a variable but ONLY the part including and after 'BEGIN:VEVENT' and ending with END:VEVENT Anything before BEGIN:VEVENT or after END:VEVENT should be ignored. Thanks for input Jeff BEGIN:VCALENDAR VERSION:2.0... (3 Replies)
Discussion started by: uptimejeff
3 Replies

5. Shell Programming and Scripting

awk - print record with both string1 and string2

How do I use awk to find the records in a file that contains two specific strings? I have tried piping and using awk two times, but I don't know how to do it in one action. (2 Replies)
Discussion started by: locoroco
2 Replies

6. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

7. UNIX for Beginners Questions & Answers

Replace string2 with string3 on all lines starting with string1

My OS is Windows 10 and I am using Cygwin. The file 1 content is: USE solution 2; -4.000 USE solution 3; -4.000 … USE solution 29; -4.000 USE solution 30; -4.000 USE solution 31; -4.000 …. USE solution 89; -4.000 ... USE solution 202; -4.000 etc... I need to replace... (8 Replies)
Discussion started by: supernono06
8 Replies

8. Shell Programming and Scripting

Replace string2 by string3 where string1 is found in line

Hello, My aim is to search string1 in all lines. When found, find and replace string2 by string3 if possible. TextFile: Here is my first line Second line with string1 & string2 Not last line but it contains string1 Expected output: Here is my first line The second line with string1 &... (6 Replies)
Discussion started by: baris35
6 Replies

9. UNIX for Beginners Questions & Answers

Replace string2 by string3 where string1 is found in line

I found this in the forum that searches a file for string1, substitute all occurrences of string2 with string3. (Title: Replace string2 by string3 where string1 is found in line) >> sed -i '/string1/s/string2/string3/g' TextFile How will I perform the same sed command and only substitute... (3 Replies)
Discussion started by: apalex
3 Replies
SSAStringCpy(3SNMP)					      SNMP Library Functions					       SSAStringCpy(3SNMP)

NAME
SSAStringCpy, SSAStringInit, SSAStringToChar, SSAStringZero - Sun Solstice Enterprise Agent string helper functions SYNOPSIS
cc [ flag ... ] file ... -lssasnmp [ library .. ] #include <impl.h> void *SSAStringZero(String *string); int SSAStringInit(String *string, uchar_t *chars, int len, char *error_label); int SSAStringCpy(String *string1, String *string2, char *error_label); char *SSAStringToChar(String string); DESCRIPTION
The SSAStringCpy() function makes a deep copy of string2 to string1. This function assumes that string1 has been processed by the SSAS- tringZero() function. Memory is allocated inside the string1 and the contents of string2, not just the pointer, is copied to the string1. If an error is encountered, an error message is stored in the error_label buffer. The SSAStringInit() function copies the char array from chars to the string instance with the specified length len. This function assumes that the string instance has been processed by the SSAStringZero() function or no memory is allocated inside the string instance. If an error is encountered, an error message is stored in the error_label buffer. The SSAStringToChar() function returns a temporary char array buffer for printing purposes. The SSAStringZero() function frees the memory inside of the String instance, but not the string object itself. RETURN VALUES
The SSAStringInit() and SSAStringCpy() functions return 0 if successful and -1 if error. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) SunOS 5.10 17 Dec 1996 SSAStringCpy(3SNMP)
All times are GMT -4. The time now is 02:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy