LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-28-2010, 06:38 AM   #1
RanjanR
LQ Newbie
 
Registered: Sep 2010
Posts: 7

Rep: Reputation: 0
Unhappy Need help in filtering some words from middle of a line! Its urgent.


Hi all,

I have a file which contains
ERROR:Could not find banner! A COTE 1
ERROR:Could not find banner! A L EGLANTINE 1
ERROR:Could not find banner! 3 M.M.M. 3
ERROR:Could not find banner! BATI BRICO 63 1

I want to extarct the letters between "ERROR:Could not find banner!" and the last number.
That means output should be

A COTE
A L EGLANTINE
3 M.M.M.
BATI BRICO 63

It would be great if anyone can help me in finding answer for this.
It is very urgent!
Thank you in advance.
Anyway..either in sed or awk or perl script is acceptable.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 09-28-2010, 06:50 AM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Why the sad face?

Here's one way, thrown together quickly - there is probably a shorter method:
Code:
 awk '{for(x=5; x<=NF-1; x++){printf $x; if(x==NF-1){printf "\n"}else{printf " "}}}' filename
In the future, please do not use "URGENT" in your thread titles; everyone's problems are equally important, and deserve equal attention by the folks volunteering their time to help.

Last edited by GrapefruiTgirl; 09-28-2010 at 06:53 AM. Reason: adjusted code to not output extra newline at end
 
2 members found this post helpful.
Old 09-28-2010, 07:19 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
Here's another couple of quick ideas:
Code:
awk 'gsub(/.*! |.$/,"")' file

sed -r 's/[^!]+! (.*)./\1/' file
And more to what GrapefruiTgirl said, urgent is only to you ... not the people giving their free time here.
 
1 members found this post helpful.
Old 09-28-2010, 07:37 AM   #4
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 45
Code:
$ ruby -F"\!\s+" -ane 'puts $F[1].split(/\s+/)[0..-2].join(" ")' file
A COTE
A L EGLANTINE
3 M.M.M.
BATI BRICO 63
 
1 members found this post helpful.
Old 09-28-2010, 07:53 AM   #5
RanjanR
LQ Newbie
 
Registered: Sep 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Talking Thank u


Thank you all...

It worked.. and sure I will not mention as urgent.

Last edited by RanjanR; 09-28-2010 at 08:00 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Display every line that does not contain one of the listed words smeezekitty Programming 4 02-18-2010 01:51 AM
break line into words nushki Programming 16 12-04-2009 10:15 AM
how to search and replace character from middle of line vishal_titre Linux - General 7 09-30-2008 03:46 AM
How do I extract characters from several words on a line? MheAd Linux - Newbie 22 06-23-2008 11:22 PM
BASH: First words in a line JordanH Programming 7 10-24-2004 11:00 AM


All times are GMT -5. The time now is 07:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration