LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-08-2006, 08:44 AM   #1
mjmwired
Member
 
Registered: Apr 2004
Distribution: CentOS6, CentOS5, F16, F15, Ubuntu, OpenSuse
Posts: 620

Rep: Reputation: 39
Reformatting help with sed or awk


Simple question for the scripting guru's. I need to reformat the following output, could someone suggest how to do this with sed or awk or some other scripting tool?

From:
Code:
compiler:"C:\dir\filename.c"line 123: error: undeclared symbol 'temp'
To:
Code:
C:\dir\filename.c(123) : error : undeclared symbol 'temp'
Thanks.
 
Old 06-08-2006, 09:06 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Code:
#!/usr/bin/perl -w


while (<>) {
    next unless /error/;

    ($file, $line, $rest) = /"(.*)"\w*line (\d+)(.*)/;
    print "$file($line) $rest";
    print "\n";

}

Last edited by bigearsbilly; 06-08-2006 at 09:07 AM.
 
Old 06-08-2006, 10:58 AM   #3
mjmwired
Member
 
Registered: Apr 2004
Distribution: CentOS6, CentOS5, F16, F15, Ubuntu, OpenSuse
Posts: 620

Original Poster
Rep: Reputation: 39
Thanks but I'm using a limited platform with a limited gnu utils and no perl.
 
Old 06-08-2006, 11:32 AM   #4
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Code:
sed -e 's/^compiler:"\([^"]*\)" *line \([0-9]*\):\(.*\)$/\1(\2) : \3/'
 
Old 06-08-2006, 12:22 PM   #5
mjmwired
Member
 
Registered: Apr 2004
Distribution: CentOS6, CentOS5, F16, F15, Ubuntu, OpenSuse
Posts: 620

Original Poster
Rep: Reputation: 39
Thanks!! It did the trick.

Works perfect in Linux and Cygwin. To get it to work in Windows cmd shell, I placed the contents into 'conv.sed' and ran:
$ sed -f conv.sed input.txt
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed and Awk Gins Programming 7 04-19-2006 10:32 AM
I have a question about awk or sed sqp1982 Programming 9 03-28-2006 05:37 AM
SED, AWK or PERL HELP embsupafly Programming 6 08-20-2005 09:07 PM
Sed & Awk hinetvenkat Linux - Software 4 05-30-2005 05:10 AM
awk/sed help pantera Programming 1 05-13-2004 11:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration