LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed (https://www.linuxquestions.org/questions/linux-newbie-8/sed-749250/)

casperdaghost 08-21-2009 05:00 AM

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

rizhun 08-21-2009 05:18 AM

Just do it with 'cut':
Code:

$ < newcomlite cut -c 4-
If you absolutely have to use 'sed':
Code:

$ sed -e 's/^\%\%p//' newcomlite

casperdaghost 08-21-2009 05:35 AM

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'

rizhun 08-21-2009 05:42 AM

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}//'

pixellany 08-21-2009 07:07 AM

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/^%%.//'


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