Hi I am Rupesh from India. I have a text file which contains filenames preceded by directories.
The text file contains the following pattern in all the lines
./a/b/c/d/e/temp.mp3.
I want to create a file with name temp.mp3 which is contained in directory e which is contained in directory d which is contained in directory c which is contained in directory b which is contained in directory a which is contained in the current directory.
I think that we can create file using touch.
I have issued the following command
touch ./a/b/c/d/e/temp.mp3
The above command displayed message as ./a/b/c/d/e/temp.mp3 not found.
Please suggest how to create filename with sub directories.
First, you should always post what you do complete here between CODE tags. Thus not that long story of you but:
henk@boven:~/test/rupesh> LANG=C touch ./a/b/c/d/e/temp.mp3
touch: cannot touch './a/b/c/d/e/temp.mp3': No such file or directory
henk@boven:~/test/rupesh>
only so can we see what you saw.
Second, read
man touch
it says that it creates FILE, not a PATH. So there is really no need to try a complete path because that does not work by definition.,
Third, you create a directory using mkdir. And a complete PATH of directories with mkdir -p, Again read
Actually the text file consists of 12000 filenames. All of you are talking about creating a single file.
May I know how to delete the last column of a file. I have read manual page and info page of cut it has specified about field option ie -f but it doesn’t describe about cutting from backwards. I have used cut to delete first column from a file and it has displayed some output showing first column of a file but when I opened the original file it is displaying the first column as before I mean first column has not been deleted.
Please try to suggest how to delete last column from a file if not atleast how to delete first column from a file. By using rev utility I can reverse all the characters present in a file and after that I can remove first column using cut then again if I use rev utility I can achieve what I want.
>
>
> Hi I am Rupesh from India. I have a text file which contains filenames
> preceded by directories.
>
> The text file contains the following pattern in all the lines
> ./a/b/c/d/e/temp.mp3.
>
> I want to create a file with name temp.mp3 which is contained in
> directory e which is contained in directory d which is contained in
> directory c which is contained in directory b which is contained in
> directory a which is contained in the current directory.
>
> I think that we can create file using touch.
>
> I have issued the following command
>
> touch ./a/b/c/d/e/temp.mp3
>
> The above command displayed message as ./a/b/c/d/e/temp.mp3 not found.
>
> Please suggest how to create filename with sub directories.
>
>
Try touch a/b/c/d/e/temp.mp3
note the missing ./
#!/bin/bash
# Counter if multiple lines to process
count=1
while IFS='' read -r line || -n "$line" ]]; do
# Check line output to process
echo "Line $count text is: $line"
# Get path and remove leading . and /
path=`echo $(dirname "${line}")| sed 's/.\///'`
echo "Path is $path"
# Make the directory tree if it exists or not
mkdir -p $path
# Get the filename
filename="${line##*/}"
echo "Filename is $filename"
# Create the filename
touch $path/$filename
count=`expr $count + 1`
done < "$1"
Make saved script executable and run with filename input;
chmod 0755 read_file
./read_file somefile.txt
Line 1 text is: ./a/b/c/d/e/temp1.mp3
Path is a/b/c/d/e
Filename is temp1.mp3
Line 2 text is: ./a/b/c/d/e/temp2.mp3
Path is a/b/c/d/e
Filename is temp2.mp3
Line 3 text is: ./a/b/c/d/e/temp3.mp3
Path is a/b/c/d/e
Filename is temp3.mp3
Line 4 text is: ./f/g/h/i/j/temp4.mp3
Path is f/g/h/i/j
Filename is temp4.mp3
Result;
ls
a f read_file somefile.txt
ls a/b/c/d/e/
temp1.mp3 temp2.mp3 temp3.mp3
ls f/g/h/i/j/
f/g/h/i/j/temp4.mp3
Hi
You seem to have some issues with this, the Forum staff don’t. Please see the forum T&C’s regarding these are technical forums for users to ask question. Help, don’t help but trolling/stalking won’t be.
First,
You’re only going to get “best effort” advice if you don’t post actual, real examples.
Do not post some general description or the only thing you’ll get is some general answer which may or may not work.
Using touch to create a file in a directory.
You can do so for any location where all directories in the path already exist.
The command will not magically create directories when you create a file.
And, it should not matter whether you include “this directory” ie ./foo
Removing "column"
Can’t possibly understand what you mean.
Again, you have to post an actual file or file name and what you want to do with it.
Don’t make people guess at what you’re asking.
Be detailed and exact about what you’re asking.
I just want to add that touch is not just for creating empty files. Creating empty files is just a bonus of touch
DESCRIPTION
Update the access and modification times of each FILE to the current time.
A FILE argument that does not exist is created empty, unless -c or -h is supplied.
A FILE argument string of - is handled specially and causes touch to change the times of the file associated with standard output.
Mandatory arguments to long options are mandatory for short options too.
The shell can create an empty file by itself, well at least POSIX shells that supports redirection ( I hope )
Redirection means using the More than > and Less than sign < (or operators as what the shell docs calls it) . In this case the more than sign is to be used.
> foo.mp3
Should create an empty file named foo.mp3.
Here is an example. First go to an empty directory and run the commands below.
mkdir -p foo/bar/baz/more/ && > "${_}foo.mp3"
tree
.
└── foo
└── bar
└── baz
└── more
└── my.mp3
4 directories, 1 file
I’m not sure if **tree **is installed by default though. Also Pathname is another word for directories since you want to separate the Filename and Pathname.
Hi
You need to show an example of the actual raw data, descriptions can be deceptive, so show the line of what you get via wget, then what the expected output your wanting.
You could paste the file “as is” into an online URL Encode/Decode utility, for example: https://www.url-encode-decode.com/ and then use the resulting plain text output. Subject to any size limitations on the conversion site of course, you may have to do it in chunks.