Sponsored Content
Full Discussion: sed searching across lines
Top Forums Shell Programming and Scripting sed searching across lines Post 302091445 by miechu on Tuesday 3rd of October 2006 04:27:58 AM
Old 10-03-2006
not quite... i have noiced, that some errors have also blank line "in" them, so i ended up writing a code that will find another "Compiling " string + added line breaking (based on words) so i can add '#' in front, and each bug is spaced with "-------------------" Smilie

if anyone is interested:

Code:
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

void print_the_line(string s)//function for line breaking
{
	if (s.size() > 70)
	{
		string out = "", tmp = "";

		for (unsigned int i = 0; i < s.size(); i++)
		{
			tmp += s[i];

			if (s[i] == ' ')
			{
				if (tmp.size() + out.size() < 70)
				{
					out += tmp;
					tmp = "";
				}
				else
				{
					cout << "# " << out << endl;			
					out = tmp;
					tmp = "";
				}
			}

		}

		cout << "# " << out << tmp << endl;
	}
	else
		cout << "# " << s << endl;
}

int main( int argc, const char* argv[] )
{
	if (argc == 1)
	{
		cerr << "Please specify the input file." << endl;
		return 1;
	}

	ifstream file;
	file.open(argv[1]);
	//file.open("error1.txt");

	if (!file.is_open())
	{
		cerr << "Couldn't open file: " << argv[1] << endl << "Terminating program." << endl;
		return 2;
	}

	std::string buf;
	std::string line;
	
	std::getline(file, line);//Compiler version info 

	print_the_line("");
	print_the_line(line);

	while (std::getline(file, line) && line.find("Oracle CORE") != 0){}//trimming the garbage
	
	print_the_line("");

	while(std::getline(file, line))
	{
		if (line.find("Compiling ") == 0)
		{
			std::getline(file, line);

			if ( line.find("No compilation errors") == string::npos )//not found - we must write the line 
			{														 //till we find another "Compiling "
				print_the_line("------------------------------------------------------------------");
				print_the_line(line);
			}
			else//we found string - everything is ok, so let's delete the blank line
			{
				std::getline(file, line);//<blank line>	
			}
		}
		else
			print_the_line(line);

	}

	print_the_line("");

	file.close();
	
	return 0;
}

but your solution is very interesting, i'm just too lame in bash to write a full script... so i eneded up mixing both...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

lines searching >>

hi guys! I`ll really appreciate your help. The situation is: i have a log file, and i need to get the needed lines from it. linecount=$(cat -n http.log | grep ALERT | awk '{print $1}' | wc -l) lines=$(cat -n http.log | grep ALERT | awk '{print $1}') 1-string gets the number of found lines... (2 Replies)
Discussion started by: neverhood
2 Replies

2. Shell Programming and Scripting

Searching for lines ending with }

I'm trying to search for lines ending with "}" with the following command but am not getting any output. grep '\}$' myFile.txt I actually want to negate this (i.e. lines not ending with "}"), but I guess that should be easier once I find the command that finds it? (11 Replies)
Discussion started by: BootComp
11 Replies

3. UNIX for Dummies Questions & Answers

Searching for lines in a file?

What is the best way to display lines in a log file that begin with a certain string? Preferably I would like to 'print' them to a file. I guess I would use 'cat' for that? There are two types of line I would like to get at - each begins with a different two words. It would be something... (8 Replies)
Discussion started by: Sepia
8 Replies

4. Shell Programming and Scripting

Sed - Pattern Searching

Hi, Please take a look at the below eg. I would like to search for abc() pattern first and then search for (xyz) in the next line. If I can find the pattern, then I should delete the 3 lines. I can only find the pattern and delete but I am unable to find two patterns and delete. Any... (8 Replies)
Discussion started by: sreedevi
8 Replies

5. Shell Programming and Scripting

Searching for lines in textfiles

Hello all, I've a problem. I've two logfiles and i need to find lines in the second file by using information from the first file. First I need to extract a searchpattern from the first file. Its like abc=searchpattern&cde=. All between abc= and &cde= is the pattern I need to find in the second... (2 Replies)
Discussion started by: Avarion
2 Replies

6. Shell Programming and Scripting

Perl searching special words in lines

Hi , i am a new with perl, i want to made a script that find in file rows that start with specil words, as an example a line will start with" ............................................. specialword aaa=2 bbb=5 ............................................. and to put this in a new file... (3 Replies)
Discussion started by: alinalin
3 Replies

7. Shell Programming and Scripting

Insert tags in lines after searching for a word

Hi, I am new to Unix and this is my first post on this forum. I am trying to convert a file into an xml. In my input I want to search for any line that starts with a 'F' and make it a tag in the xml. See below for the input and output. Input : <Payment> <REFERENCE>78</REFERENCE> F123 : ... (7 Replies)
Discussion started by: akashgov
7 Replies

8. Shell Programming and Scripting

Searching inverted lines

Hi fellas, I have a file like this: A_B B_D C_D D_B E_F G_H B_A F_E In other words, I have member1_member2 and member2_member1 in the same file. In the exemple aforementioned I have A_B and B_A, B_D and D_B, E_F and F_E. So, I would like to know a sript that print the lines B_A, D_B... (3 Replies)
Discussion started by: valente
3 Replies

9. UNIX for Dummies Questions & Answers

Add lines after searching for a pattern

Hi, I have 2 files like below. File A: apple mango File B: start abc def apple ghi end start cba fed (4 Replies)
Discussion started by: jayadanabalan
4 Replies

10. Shell Programming and Scripting

Searching for pattern and remove the lines

Hi , I want to remove the specific pattern and remove those lines from file using shell script. i want to remove these lines <?xml version='1.0' encoding='UTF-8'?> <row_set> </row_set> my input file has content like this. file name: sample.xml <?xml version='1.0'... (4 Replies)
Discussion started by: nukala_2
4 Replies
copymsg(9F)						   Kernel Functions for Drivers 					       copymsg(9F)

NAME
copymsg - copy a message SYNOPSIS
#include <sys/stream.h> mblk_t *copymsg(mblk_t *mp); INTERFACE LEVEL
Architecture independent level 1 (DDI/DKI). PARAMETERS
mp Pointer to the message to be copied. DESCRIPTION
copymsg() forms a new message by allocating new message blocks, and copying the contents of the message referred to by mp (using the copyb(9F) function). It returns a pointer to the new message. RETURN VALUES
If the copy is successful, copymsg() returns a pointer to the new message. Otherwise, it returns a NULL pointer. CONTEXT
copymsg() can be called from user or interrupt context. EXAMPLES
Example 1: : Using copymsg The routine lctouc() converts all the lowercase ASCII characters in the message to uppercase. If the reference count is greater than one (line 8), then the message is shared, and must be copied before changing the contents of the data buffer. If the call to the copymsg() function fails (line 9), return NULL (line 10), otherwise, free the original message (line 11). If the reference count was equal to 1, the message can be modified. For each character (line 16) in each message block (line 15), if it is a lowercase letter, convert it to an upper- case letter (line 18). A pointer to the converted message is returned (line 21). 1 mblk_t *lctouc(mp) 2 mblk_t *mp; 3 { 4 mblk_t *cmp; 5 mblk_t *tmp; 6 unsigned char *cp; 7 8 if (mp->b_datap->db_ref > 1) { 9 if ((cmp = copymsg(mp)) == NULL) 10 return (NULL); 11 freemsg(mp); 12 } else { 13 cmp = mp; 14 } 15 for (tmp = cmp; tmp; tmp = tmp->b_cont) { 16 for (cp = tmp->b_rptr; cp < tmp->b_wptr; cp++) { 17 if ((*cp <= 'z') && (*cp >= 'a')) 18 *cp -= 0x20; 19 } 20 } 21 return(cmp); 22 } SEE ALSO
allocb(9F), copyb(9F), msgb(9S) Writing Device Drivers STREAMS Programming Guide SunOS 5.10 27 Jun 1995 copymsg(9F)
All times are GMT -4. The time now is 10:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy