ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If you type in the console `help read | less', you'll probably see the following:
Quote:
$ help read
read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
Read a line from the standard input and split it into fields.
Reads a single line from the standard input, or from file descriptor FD
if the -u option is supplied. The line is split into fields as with word
splitting, and the first word is assigned to the first NAME, the second
word to the second NAME, and so on, with any leftover words assigned to
the last NAME. Only the characters found in $IFS are recognized as word
delimiters.
....
So, `read' reads from standard input. If you want to read from file, just redirect it to standard input:
1. i didnt understand this example "$ echo "abc-def.ghi" | cut -d- -f2 | cut -d. -f1" ,i didnt understand why do i need the middle cut? and what is the input to this cut?
1. i didnt understand this example "$ echo "abc-def.ghi" | cut -d- -f2 | cut -d. -f1" ,i didnt understand why do i need the middle cut? and what is the input to this cut?
The pipe (|) takes standard output of the command on the left and makes it the standard input to the command on the right. So, in the example, the echo created the input to the first cut, that first cut split the input into two parts, abc and def.ghi, and passed the def.ghi down the pipe to the second cut. Then the second cut split the def.ghi and printed the first part, the def.
Quote:
2.how can i refer as input to cut the file-name?
That, of course, depends on the script you are writing. If you are reading the file names from a file (As suggested by the question with which you started this thread.), something like this might be what you want:
Code:
#!/bin/bash
while read line
do
for p in $(echo line | cut -d. -f1 | cut -d- -f1,2 --output-delimiter=" ")
do
echo ${p}
done
done < input_file_name
(Where, of course, you would replace the echo ${p} with whatever you wanted to do with each part of the file names from the input file.)
The pipe (|) takes standard output of the command on the left and makes it the standard input to the command on the right. So, in the example, the echo created the input to the first cut, that first cut split the input into two parts, abc and def.ghi, and passed the def.ghi down the pipe to the second cut. Then the second cut split the def.ghi and printed the first part, the def.
That, of course, depends on the script you are writing. If you are reading the file names from a file (As suggested by the question with which you started this thread.), something like this might be what you want:
Code:
#!/bin/bash
while read line
do
for p in $(echo line | cut -d. -f1 | cut -d- -f1,2 --output-delimiter=" ")
do
echo ${p}
done
done < input_file_name
(Where, of course, you would replace the echo ${p} with whatever you wanted to do with each part of the file names from the input file.)
HI
first of all thanks you all for your help...
second, the solution that you suggested it is not solve my problem...
because the file locted in a library and their names are not locaed in a spesific file...
second, the solution that you suggested it is not solve my problem...
because the file locted in a library and their names are not locaed in a spesific file...
is there any solution for this problem?
thanks in advance
Sure. In place of < input_file_name use something like < $(ls -1 folder*-*.*) where folder is the name of the library containing the files. To see what the input would be, just run the command inside the $() expression from a command line. (Note that the option is -"number one" not -"letter L".)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.