Re: Delete the path
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 08/31/04
- Next message: Stephane CHAZELAS: "Re: Can I put a ^M on a command line somehow?"
- Previous message: JuanL: "Delete the path"
- In reply to: JuanL: "Delete the path"
- Next in thread: Ed Morton: "Re: Delete the path"
- Reply: Ed Morton: "Re: Delete the path"
- Reply: JuanL: "Re: Delete the path"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 Aug 2004 09:39:20 GMT
On 2004-08-31, JuanL wrote:
> Hi,
>
> I have a list of files in a txt file (ls -l *.txt > File.txt ) and I
> want to cut their path and
> save the new list into another file.
>
> File.txt:
> /path1/xxx/tmp_001.txt
> /path1/xxx/tmp_002.txt
> /path1/xxx/tmp_003.txt
>
> I have tried the following:
>
> tr -d '/path1/xxx/' < File.txt > NewFile.txt
>
> The problem with that is that NewFile.txt will be:
> tmp_00.txt <---- tr -d finds the '1' and replace it
> tmp_002.txt
> tmp_003.txt
tr is for translating characters, not strings.
This sed commands removes everything up to the final slash on each
line:
sed 's|.*/||' File.txt
Or you could use awk:
awk 'sub(/.*\//,"")' File.txt
Or you could use a shell loop:
while IFS= read -r line
do
printf "%s\n" "${line##*/}
done < File.txt
Or a filter in C ....... [OT - available on request]
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: Stephane CHAZELAS: "Re: Can I put a ^M on a command line somehow?"
- Previous message: JuanL: "Delete the path"
- In reply to: JuanL: "Delete the path"
- Next in thread: Ed Morton: "Re: Delete the path"
- Reply: Ed Morton: "Re: Delete the path"
- Reply: JuanL: "Re: Delete the path"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|