The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
searching for content of files Aretai UNIX for Dummies Questions & Answers 19 03-09-2007 06:44 AM
grep/cat/more -- search in a txt file and display content from a specific "keyword" I-1 UNIX for Dummies Questions & Answers 4 02-21-2007 04:57 AM
Cleaning the content of log files jyotipg Shell Programming and Scripting 1 11-15-2006 02:19 AM
content need changes- many files swchee Shell Programming and Scripting 3 10-05-2006 12:29 PM
Compare the content of 2 files odogbolu98 Shell Programming and Scripting 3 09-10-2002 11:44 AM

Closed Thread
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 Rating: Thread Rating: 2 votes, 3.00 average. Display Modes
  #1 (permalink)  
Old 01-08-2009
dndoon dndoon is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 12
Unhappy display files name and it's content

hello,

i have a question and i'll be appreciated if you can help me with this.

i have i folder let's say "users"
in this folder there are files (file1, file2, file2, etc) and in each file there is a number (lets say 4 in file1)

i want to display some thing like bellow

file1 4
file2 3
file3 2
file4 1

i want also the files names to be sorted alphapitical order..

Is this possible ! (using shell script)
Thanks a lot.
  #2 (permalink)  
Old 01-08-2009
pmm pmm is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 50
Assuming files in current directory and each file consists of the number as in question:

nawk ' { print FILENAME " " $1 } ' `ls` | sort

gives:

file1 4
file2 3
file3 2
file4 1
  #3 (permalink)  
Old 01-08-2009
dndoon dndoon is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 12
thanks for your replay pmm but what if i want to specify the directory path !

regards
  #4 (permalink)  
Old 01-09-2009
pmm pmm is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 50
The ls command can be used to retrieve any files required from any directory:

nawk ' { print FILENAME " " $1 } ' `ls files/file*` | sort
  #5 (permalink)  
Old 01-09-2009
dndoon dndoon is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 12
wow
Thanks a lot pmm, this was very helpfull... i got the bellow

myfiles/file1 4
myfiles/file2 3
myfiles/file3 2
...

can i display this result with any kind of format! like

file name value
file1 4
file2 3
file3 2

and so on

Regards
  #6 (permalink)  
Old 01-11-2009
pmm pmm is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 50
Ok - try this

nawk ' { print FILENAME "/" $1 }' `ls files/file*` | sort | nawk -F/ '
BEGIN { printf "%10s\t%10s\n","Filename","Value" }
{ printf "%10s\t%10s\n",$(NF-1),$NF } '

First nawk does as previous but makes output:
myfiles/file1/1
etc.
Second nawk does formatting with prints, printing header in BEGIN section, then format printing second last and last fields.
  #7 (permalink)  
Old 01-11-2009
dndoon dndoon is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 12


thanks a lot pmm

this realy helpfull... i spent hours to find a way to do that.... i really appreciate your help

Regards
Closed Thread

Bookmarks

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 04:51 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