Re: Delete the path
From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 08/31/04
- Next message: Stephane CHAZELAS: "Re: How can I findout the length of the file in shell script"
- Previous message: Ed Morton: "Re: (patch for bash) Turbo Tax tax preparation module"
- In reply to: Chris F.A. Johnson: "Re: Delete the path"
- Next in thread: Stephane CHAZELAS: "Re: Delete the path"
- Reply: Stephane CHAZELAS: "Re: Delete the path"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 31 Aug 2004 07:51:30 -0500
Chris F.A. Johnson wrote:
> 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
IMHO, this would be the more typical way:
awk -F/ '{print $NF}' File.txt
> Or you could use a shell loop:
>
> while IFS= read -r line
> do
> printf "%s\n" "${line##*/}
or
basename "$line"
> done < File.txt
>
You could just use:
xargs basename < File.txt
if your file/dir names don't contain white-space.
Regards,
Ed.
- Next message: Stephane CHAZELAS: "Re: How can I findout the length of the file in shell script"
- Previous message: Ed Morton: "Re: (patch for bash) Turbo Tax tax preparation module"
- In reply to: Chris F.A. Johnson: "Re: Delete the path"
- Next in thread: Stephane CHAZELAS: "Re: Delete the path"
- Reply: Stephane CHAZELAS: "Re: Delete the path"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|