Register
It is currently Thu Dec 18, 2014 5:15 pm

cat or awk to display some informations


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Wed Jul 17, 2013 9:52 am   

Joined: Tue Dec 11, 2007 10:21 pm
Posts: 20
Hello , i need a bit of help with cat or awk to display some informations
for example into a txt i have this information:

/home/user/www/folder

how can i display into a new text the user?

user can be changed always so , i dont know when user is user or not user2 user3 user4 , each time in the file is a different user , if where one user , the script where easy to extract , does anyone has any ideea , how can i extract just that word without search for it , using cat or awk or sed? i googled it but i found nothing good yet.

thanks for anyhelp.


Top
 Profile  
 PostPosted: Wed Jul 17, 2013 10:58 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
hi,

cat doesn't diplay some informations, it prints whole files
grep, sed, and awk can, based on regex.

a hint : the name of user is between the second and the third slash.

I suggest you use sed for simple match and print.


Top
 Profile  
 PostPosted: Wed Jul 17, 2013 8:48 pm   

Joined: Tue Dec 11, 2007 10:21 pm
Posts: 20
Hi , thanks , i have try with sed i have no success till now ,


Top
 Profile  
 PostPosted: Thu Jul 18, 2013 10:28 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
Code:
echo "/home/user/www/folder" |sed 's|/[^/]*/\([^/]*\)/.*|\1|'
user
it's also doable with bash:
Code:
IFS='/' read -a ar <<<"/home/user/www/folder"
echo "${ar[2]}"
user


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron


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