![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| find and replace string in a directory files | koti_rama | Shell Programming and Scripting | 2 | 05-30-2008 03:48 AM |
| Find and replace a string in multiple files | pharos467 | UNIX for Dummies Questions & Answers | 2 | 11-05-2007 11:47 PM |
| replace character in a string pattern and save the change in same file | mihir0011 | Shell Programming and Scripting | 2 | 09-26-2007 05:31 PM |
| replace first character of string sed | prkfriryce | Shell Programming and Scripting | 6 | 08-03-2007 02:07 PM |
| how to find and replace string | mridula | High Level Programming | 3 | 08-17-2006 04:44 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Find and replace character in a string
Hi all,
My problem is the following: I've a script that must list all files in a directory and write this information in a text file. I've tried to get the list through ls command and then write it using msgecho msgecho "`ls $PATH_APS_JOB_ORA`" This works good but the created string is very long, having the line with all files in the list separated by a blank space. Is it possible to store the ls results in a string variable, replace the space with \n and then write it into the text file? In this way, the text file will be more and more clear... I've read about sed and grep commands: is it possible to apply them to a string? How? Thanks to all will help. |
|
||||
|
Hi,
If the maxdepth option does not work for find on your OS, use the below command find /Required_Directory/ -type f -exec basename {} \; > file But this will give you the files recurrsively present inside directories inside the actual directory. If you need files only in the required directory,use the below command. ls -l /Required_Directory/ | grep "^-" | tr -s " " | cut -d" " -f8 > file check if the 8th field is filename, if not change the field number. For your clarification, "basename" command will give you strips the directory path and gives only the filename. |
|
||||
|
A new question!!!
Hi,
a new problem was born. the code you suggested works very good but now I'm trying to list in the text file more than one file list. If I repeat the operation two times, calling the ls command on two different folders, the text file is overwritten and the first data are lost... How to write in append mode on the text file? In alternative, is it possible to specify two or more different folders in ls command? Thanks in advance! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|