Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 15-10-2010, 06:04 PM   #1 (permalink)
java is fun.
 
digitalage's Avatar
 
Join Date: Jul 2008
Location: ONLINE
Posts: 85
Question Unix Script- Cut the portion of a file


Hi

I am having a file with the following content(its created by ls of a directory):

-rw-r----- 1 321 321 0 Oct 14 10:41 xcv23456
-rw-r----- 1 321 321 0 Oct 14 10:41 xcv23457
-rw-r----- 1 321 321 0 Oct 14 10:41 xcv23458
-rw-r----- 1 321 321 0 Oct 14 12:19 xcv23459
-rw-r----- 1 321 321 0 Oct 15 11:19 xcv23460



last column ie 9th column contains the file names.

I am searching for a script which can cut the last 5 digits of each row and store it in a seperate variable.

Thanks in advance
digitalage is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 15-10-2010, 06:43 PM   #2 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
Default Re: Unix Script- Cut the portion of a file

Code:
#!/usr/bin/env python
L = [i.rstrip().split()[8][-5:] for i in open('old.txt')]
print L
The data is stored in the list.
Not really an elegant way though.

EDIT: I guess this will do. All those last 5 characters from each row in the 9th column will be stores in the list L
__________________
Experience true education in Computer Science - http://www.udacity.com | http://www.coursera.org

Spoiler:
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.
Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.
Liverpool_fan is offline   Reply With Quote
Old 19-10-2010, 12:04 PM   #3 (permalink)
Wise Old Owl
 
pulkitpopli2004's Avatar
 
Join Date: Jul 2010
Location: D!ll!
Posts: 1,131
Default Re: Unix Script- Cut the portion of a file

the same cud be written in PERL langauge
considering file name to "datafile"

code:
@result="";
$path="<dir_name>/datafile";
open(FILE, "datafile");
while($line=<FILE>) {
@words=split(/ /,$line);
if($words[8] =~ /([\d]+)/) {
push result,$1;
}
print("@result \n");
pulkitpopli2004 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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


 
Latest Threads
- by Charan
- by Charan
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 03:23 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2