The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script help to eliminate files of todays date richM Shell Programming and Scripting 2 04-20-2009 04:40 AM
Combine fields and eliminate white space ski UNIX for Dummies Questions & Answers 2 07-25-2008 01:03 PM
Cannot redirect ouput????? minifish Shell Programming and Scripting 3 02-20-2008 12:15 PM
Eliminate variable checking in a script BMetelsky Shell Programming and Scripting 8 12-04-2007 10:59 AM
Red Hat - ouput capture juxtaman UNIX for Dummies Questions & Answers 3 04-10-2003 11:31 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-22-2009
Scrutinizer Scrutinizer is online now
Registered User
  
 

Join Date: Nov 2008
Posts: 761
Hello ghostdog74, I am not sure what you mean:

Code:
$> echo 'Sun Jan 11 /a.b 11:20:10 2009 1 0 /home/output/file2311_recent.list.list user1.bla user2 0 done' |grep -o '/[^.]*[^ ]*'
/a.b
/home/output/file2311_recent.list.list

  #2 (permalink)  
Old 10-23-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,098

Code:
awk '{for(i=8;i<=NF-4;i++)
        printf $i" "
        printf "\n"
        }'

  #3 (permalink)  
Old 10-22-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,558
pls see below simulation

Code:
$ more file
Sun Jan 11 11:20:10 2009 1 0 /home/output/file2311_recent.list user1 user2 0 done
Sun Jan 11 11:20:10 2009 1 0 /home/output/file2312 jan recent.list firstname.lastname user2 0 done
Sun Jan 11 11:20:10 2009 1 0 /home/output/Output.2313 feb recent.text user1 user2 0 done
$ grep -o '/[^.]*[^ ]*' file
/home/output/file2311_recent.list
/home/output/file2312 jan recent.list
/home/output/Output.2313

first two is ok, last is not. because there is "." in file name. whereas going by fields, results should always be consistent

Code:
#  python -c "for line in open('file'): print ' '.join(line.split()[7:-4])"
/home/output/file2311_recent.list
/home/output/file2312 jan recent.list
/home/output/Output.2313 feb recent.text


Last edited by ghostdog74; 10-22-2009 at 02:48 AM..
  #4 (permalink)  
Old 10-22-2009
rveri rveri is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 14
All the codes are great, Many Thanks!,
Scrutinizer , thanks for explaining the regular expression, it is crystal clear .

Thanks Ghostdog74 for pointing out the extra dot in file name issue(.)
The idea with eliminating the left and right fields and keeping the desired one makes it perfect. sed is fine except the extra . , nawk couldnt check, rev & python worked very well, Tx. Rveri.
Reply

Bookmarks

Tags
scripting, sed awk shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0