LinuxQuestions.org
Review your favorite Linux distribution.
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-19-2011, 12:09 PM   #1
random0munky
LQ Newbie
 
Registered: Jul 2011
Location: Washington, USA
Distribution: Ubuntu, CentOS, FreeBSD
Posts: 22

Rep: Reputation: Disabled
sed unterminated `s' command


Hi,

I searched through the forums and google to try and find a resolution to my particular issue, but unfortunately I haven't been able to come across one. Here's what I have right now:

Code:
echo -e "Count\tDate\tHour"

for line in `cat ./report_activity | grep session_completed | awk '{ print $3 }'`
do
 # count
 Count=0
 # date
 Date=`echo $line | sed s/[//`
 echo $Date
 # hour
done
What the line reads after I cat and grep it out:
[17/Aug/2011:14:15:46
Trying to remove the front box parens.

Thanks

random0munky
 
Old 08-19-2011, 12:15 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
if you're looking for a literal [ then escape it. Date=`echo $line | sed -e 's/\[//'`

btw, don't use `backticks`, use $(parenthesis) instead, it's much clearer and more powerful.

Last edited by acid_kewpie; 08-19-2011 at 12:17 PM.
 
1 members found this post helpful.
Old 08-19-2011, 12:16 PM   #3
slugmax
Member
 
Registered: Nov 2008
Location: Northern CT
Distribution: Slackware, Debian, Ubuntu
Posts: 69

Rep: Reputation: 25
You want:

Code:
Date=`echo $line | sed -e 's/\[//'`
Adding a '-e', wrapping the entire sed expression in single quotes, and escaping the left-bracket, as it would normally be interpreted as the start of a regular expression character class. Edit to add - the '-e' isn't strictly necessary with one expression. The end result is the same.

Last edited by slugmax; 08-19-2011 at 12:23 PM.
 
1 members found this post helpful.
Old 08-19-2011, 12:20 PM   #4
random0munky
LQ Newbie
 
Registered: Jul 2011
Location: Washington, USA
Distribution: Ubuntu, CentOS, FreeBSD
Posts: 22

Original Poster
Rep: Reputation: Disabled
Ah thank you very much. How would I use the same line without backticks. If possible, can you link me a page on how it's more powerfule << linux script noobie here just starting to learn

Thanks

random0munky
 
Old 08-19-2011, 12:33 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
you just replace the backticks with $( at the start, and ) at the end. One of the best things is that as the start is diffrent to the end, you can next them... "$(command_one -a -b $(command_two) -c -d )" etc...
 
1 members found this post helpful.
Old 08-19-2011, 12:36 PM   #6
random0munky
LQ Newbie
 
Registered: Jul 2011
Location: Washington, USA
Distribution: Ubuntu, CentOS, FreeBSD
Posts: 22

Original Poster
Rep: Reputation: Disabled
Ah that's pretty cool with having nested commands and if piping isn't a viable option. Thanks. I'll look more into using that syntax. Do you happen to know if using the $( command ) vs ` command ` is more resource intensive than the other?

random0munky

Quote:
Originally Posted by acid_kewpie View Post
you just replace the backticks with $( at the start, and ) at the end. One of the best things is that as the start is diffrent to the end, you can next them... "$(command_one -a -b $(command_two) -c -d )" etc...
 
Old 08-19-2011, 12:37 PM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
no, it's just a newer syntax (well, a decade +) no overheads.
 
1 members found this post helpful.
Old 08-19-2011, 12:43 PM   #8
random0munky
LQ Newbie
 
Registered: Jul 2011
Location: Washington, USA
Distribution: Ubuntu, CentOS, FreeBSD
Posts: 22

Original Poster
Rep: Reputation: Disabled
Ah gotcha gotcha. Thanks mate. I'll be sure to remember this and thanks everyone for the help =) Greatly appreciated

random0munky

Quote:
Originally Posted by acid_kewpie View Post
no, it's just a newer syntax (well, a decade +) no overheads.
 
  


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
Problem using sed with variable created using xargs - unterminated error wrankin Programming 5 11-14-2011 08:53 PM
[ASK] unterminated call to function `shell': missing?? arfal Linux - Server 1 12-15-2010 11:22 AM
sed: Unterminated 's' command whatis Programming 2 11-02-2009 03:19 AM
sed command ancys Programming 5 08-04-2006 12:39 AM
sed command pazvant Linux - Software 2 05-09-2004 01:58 PM


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

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