LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 11:09 AM   #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, 11:15 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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 11:17 AM.
 
1 members found this post helpful.
Old 08-19-2011, 11:16 AM   #3
thinknix
Member
 
Registered: Nov 2008
Distribution: Lots!
Posts: 178

Rep: Reputation: 58
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 thinknix; 08-19-2011 at 11:23 AM.
 
1 members found this post helpful.
Old 08-19-2011, 11:20 AM   #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, 11:33 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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, 11:36 AM   #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, 11:37 AM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
no, it's just a newer syntax (well, a decade +) no overheads.
 
1 members found this post helpful.
Old 08-19-2011, 11:43 AM   #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



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 07:53 PM
[ASK] unterminated call to function `shell': missing?? arfal Linux - Server 1 12-15-2010 10:22 AM
sed: Unterminated 's' command whatis Programming 2 11-02-2009 02:19 AM
sed command ancys Programming 5 08-03-2006 11:39 PM
sed command pazvant Linux - Software 2 05-09-2004 12:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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