LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-21-2009, 05:00 AM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 346

Rep: Reputation: 16
sed


this is from my error log

01:37:17.872 newcomm:time out sending class %%c1360 to %%p41597
01:37:17.872 newcomm:time out sending class %%c1360 to %%p30103
01:37:17.872 newcomm:time out sending class %%c1360 to %%p26525
01:37:17.872 newcomm:time out sending class %%c1360 to %%p52258
01:37:17.872 newcomm:time out sending class %%c1360 to %%p26526
01:37:17.872 newcomm:time out sending class %%c1360 to %%p26526
01:37:17.853 newcomm:time out sending class %%c1360 to %%p35299
01:37:17.888 newcomm:time out sending class %%c1360 to %%p41755
01:37:17.888 newcomm:time out sending class %%c1360 to %%p41755

i printed out the last column with awk :

casper@dots11> awk ' {print $8 }' newcomtime.txt
%%p35299
%%p41597
%%p30103
%%p26525
%%p52258
%%p26526
%%p26526
%%p41755
%%p41755

then needed to take off the first three characters of each line ( %%p) to just get the pid
I could not do it - i ended up modifying the file in kedit.

I thought that this was the sed command to take off the first three characters - what does this sed command say - how could i have deleted the first three characters of each line

casper@dots11> sed 's/\(...\).*/\1/ ' newcomlite
%%p
%%p
%%p
%%p
%%p
%%p
%%p
%%p
%%p
 
Old 08-21-2009, 05:18 AM   #2
rizhun
Member
 
Registered: Jun 2005
Location: England
Distribution: Ubuntu, SLES, AIX
Posts: 268

Rep: Reputation: 47
Just do it with 'cut':
Code:
$ < newcomlite cut -c 4-
If you absolutely have to use 'sed':
Code:
$ sed -e 's/^\%\%p//' newcomlite

Last edited by rizhun; 08-21-2009 at 05:22 AM.
 
Old 08-21-2009, 05:35 AM   #3
casperdaghost
Member
 
Registered: Aug 2009
Posts: 346

Original Poster
Rep: Reputation: 16
the cut is a good option,

I just thought that i was subsistuting the first three characters with blank lines with the s/\(...\)

maybe there is a way i could delete the first threee characters with 'd'
 
Old 08-21-2009, 05:42 AM   #4
rizhun
Member
 
Registered: Jun 2005
Location: England
Distribution: Ubuntu, SLES, AIX
Posts: 268

Rep: Reputation: 47
I'd guess the '%' sign isn't classed as a standard character and therefore isn't being matched by the '.' -- you'll have to check the 'sed' documentation to be sure though.

If it was you could catch it with -- sed -e 's/^.{3}//'

Last edited by rizhun; 08-21-2009 at 05:43 AM.
 
Old 08-21-2009, 07:07 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
casper@dots11> sed 's/\(...\).*/\1/ ' newcomlite
This says KEEP the first 3 characters. You are using a "backreference" in which everything inside \(\) is repeated using \1.

It is matching the "%" just fine----in your example, you are getting the expected output.

rizhun's example above should work, except that it would need the -r flag:
sed -e -r 's/^.{3}//'

You could also use something like:
sed 's/^%%.//'
 
  


Reply

Tags
cut


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
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
help with sed ojschubert Linux - Newbie 7 03-01-2005 05:18 PM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM


All times are GMT -5. The time now is 02:59 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration