LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-07-2015, 11:30 PM   #1
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Rep: Reputation: 47
sed problem


I'm trying this:

more file.log | sed -n -e '/`date +"%b %Oe"`/,$p'

but it doesn't work. can someone help me? thanks.
 
Old 03-08-2015, 12:10 AM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
sed -n -e '/`date +" file.log

more isn't outputting anything for sed to chew on.
 
Old 03-08-2015, 12:17 AM   #3
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,379

Rep: Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757
Check your sed expression. I think you have the capital letter O, when you really want the numeral zero.
 
Old 03-08-2015, 12:29 AM   #4
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
@dijetlo
more is working, file is there.

@allend
I need single digit day. its the same problem with or without O.
 
Old 03-08-2015, 01:16 AM   #5
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Sorry
I'm not a sed expert, so I took a loot at your date formatting.


however if I had to guess(again)
that
Quote:
+" b Oe"
should be this
Quote:
"+%b %Oe"
since the date interprets '+' as the switch and therefor a string,

(is it just me or is everyone getting their "%"s stripped out of their posts...)

Last edited by dijetlo; 03-08-2015 at 01:51 AM. Reason: simpler skips formatting issues
 
Old 03-08-2015, 01:55 AM   #6
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,379

Rep: Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757
I am not sure what formatting you want, so some quick tests.
Code:
bash-4.3$ date +%b%e
Mar 8
bash-4.3$ date +%b%0e
Mar08
bash-4.3$ date +%b%-e
Mar8
bash-4.3$ date +"%b %e"
Mar  8
bash-4.3$ date +"%b %0e"
Mar 08
bash-4.3$ date +"%b %-e"
Mar 8
From 'man date'
Quote:
By default, date pads numeric fields with zeroes. The following optional flags may follow '%':
- (hyphen) do not pad the field
_ (underscore) pad with spaces
0 (zero) pad with zeros

Last edited by allend; 03-08-2015 at 01:58 AM.
 
Old 03-08-2015, 01:57 AM   #7
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
thats all fine, date works as expected, but sed doesn't. I even tried assigning variable and using:

more file.log | sed -n -e '/`$var1`/,$p'

but that fails too.
 
Old 03-08-2015, 03:05 AM   #8
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,379

Rep: Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757
Please post a sample from the log that you are trying to interrogate, obfuscating any sensitive information.
Also, please read djetlo's comment in post #2.
 
Old 03-08-2015, 03:26 AM   #9
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
moving the + didn't solve anything. If I copy/paste the output of date command into sed it works nice.
for some reason backticks fail in sed?
 
Old 03-08-2015, 03:43 AM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,147

Rep: Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124
try
Code:
sed -n -e "/$var1/,$ p" file.log
more is unneeded, and note carefully the changes.
 
1 members found this post helpful.
Old 03-08-2015, 03:48 AM   #11
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
thanks, that does work. I used more, because piping is needed.
edit: it works with `date...` too, now.

Last edited by qrange; 03-08-2015 at 03:50 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] sed problem battles Linux - Newbie 1 02-22-2015 11:01 AM
problem with sed eradev *BSD 2 05-03-2010 11:48 AM
sed problem kazemipouya Linux - Newbie 4 08-18-2009 03:37 AM
sed problem fossilet Linux - Software 4 12-26-2004 05:44 AM
Help Sed Problem anirudh Linux User Groups (LUG) 1 08-30-2004 02:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:23 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