Meaningless Drivel is fun!*
The moose likes Linux / UNIX and the fly likes doubt with this shell script unix command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "doubt with this shell script unix command" Watch "doubt with this shell script unix command" New topic
Author

doubt with this shell script unix command

preethi kumar
Ranch Hand

Joined: Jun 04, 2010
Posts: 50
find . -name "*" -type f gives me the below output

./test3.php
./test2.php
./test1.php


i want to pipe some command in such a way that my output should be

test3.php
test2.php
test1.php

and the number of php files and lines can change. so how do i write a general linux command?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

There are a number of ways to do this. The one I think of is to use sed to remove the first two characters from each line:

find . -name "*" -type f | sed 's/^..//'


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923



This works for gnu-find. Your find might differ.

Instead of piping, it is often, but not always, a good idea, to use one of the switches: -exec, -execdir, -ok, -okdir. It isn't trivial to use, but powerful.


http://home.arcor.de/hirnstrom/bewerbung
preethi kumar
Ranch Hand

Joined: Jun 04, 2010
Posts: 50
Thank you guys. your response really helped .
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doubt with this shell script unix command
 
Similar Threads
Splitting Source and Class Code
Constructor
passing in a file from the command line
Unix Ksh split command
define method execute order in java