Register
It is currently Mon Sep 01, 2014 12:33 pm

Help with AWK and SED


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Tue Nov 26, 2013 12:26 pm   
User avatar

Joined: Tue Nov 26, 2013 12:19 pm
Posts: 5
Location: Belgrade, Serbia
Hi,

it's my first post here. I need help on two things.
First, I need awk to show (with the help of a date command):
  • only time
  • only time zone
  • to take day, month and year and show them in the order day.month.year

Second, as you know from the C programming language, comments start with the // characters, if it's just 1 line of comments.
I need to write the sed command which transforms // comments into /* */.

I'm completely helpless, so please help me if you can. Thanks!


Top
 Profile WWW YIM  
 PostPosted: Tue Nov 26, 2013 6:01 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Hi,

I don't really get your first request. Do you mean what follows?
Code:
date +%T # time
date +%Z # time zone abbr.
date +%d.%m.%y # date

Homework?


As for the second, sed(1) does easily do the job for simple cases:
Code:
sed -i.bak 's,//\(.*\)$,/*\1 */,' file.c

...but it's a pain for complex ones.


Use uncrustify(1) to manage (almost) every case:
Code:
uncrustify -q -c <(echo cmt_cpp_to_c=1) --suffix=.tmp file.c && mv "$_"{.tmp,}


This turns, e.g.:
Code:
#include <stdlib.h>

// //
int main(void)
{
   char const *const s = "//* foo // */*"; //

   // /** */
   (void)s; //* /*
   return EXIT_SUCCESS; // / *b//a/ ** /r* / *//
}

...into:
Code:
#include <stdlib.h>

/* // */
int main(void)
{
   char const *const s = "//* foo // */*"; /*  */

   /* / ** * / */
   (void)s; /* * / * */
   return EXIT_SUCCESS; /* / *b//a/ ** /r* / * // */
}


Top
 Profile  
 PostPosted: Wed Nov 27, 2013 9:01 am   
User avatar

Joined: Tue Nov 26, 2013 12:19 pm
Posts: 5
Location: Belgrade, Serbia
Hey, thanks! It worked. Yes, it was homework.
One more question, for anyone who may know: do you know how I can get the 'common-licenses' folder in the /usr/share/ directory? Because I have this task: use the 'grep' command to find "copyright" in files with licenses found in the /usr/share/common-licenses directory. Which option needs to be used in order to show the number of lines in which the word has been found, too? By option, she (my professor) means one of the 'grep' options that start with a dash sign. The problem is, there is NO common-licenses directory in the 'share' folder.

Anyone knows what the problem may be? Thanks!


Top
 Profile WWW YIM  
 PostPosted: Wed Nov 27, 2013 1:09 pm   
User avatar

Joined: Tue Nov 26, 2013 12:19 pm
Posts: 5
Location: Belgrade, Serbia
Hey, jsz.

I remembered now that I should've used the 'awk' command to separate the parts of date I need from the 'date' command output. Do you know, by any chance, how I should do that? Or anyone else? I'm told to use the 'awk' command to separate the part I need from the 'date' command output. That's it.


Top
 Profile WWW YIM  
 PostPosted: Fri Nov 29, 2013 5:17 pm   
User avatar

Joined: Tue Nov 26, 2013 12:19 pm
Posts: 5
Location: Belgrade, Serbia
Bump.


Top
 Profile WWW YIM  
 PostPosted: Mon Dec 02, 2013 5:22 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Well, after you tried so hard to do your homework yourself I feel very surprised that nobody wants to do it for you...


Top
 Profile  
 PostPosted: Mon Dec 02, 2013 1:35 pm   
User avatar

Joined: Tue Nov 26, 2013 12:19 pm
Posts: 5
Location: Belgrade, Serbia
DarthWavy wrote:
Well, after you tried so hard to do your homework yourself I feel very surprised that nobody wants to do it for you...


As a matter of fact, I already finished my homework by myself. I just didn't post my work.

Thanks anyway.


Top
 Profile WWW YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP