Output a list of five books with their filename titles into one file
Dear unix forum,
could I output a list of five books with their file name titles into one file?
In order o output all the contents of all the files with their file names there was:
In spite of them being successively named 1Atitle... 2Atitle the two first aren't 1A 2A, but 1A ..5A (2
3 4) They actually are: 1АБетховен.. 5АБетховен... It now breaks all things I hoped.
Could the task be done by head, cat or grep command? Cat has no file name parameter, head can't output the whole file and grep has a file name parameter but it's primary use is searching one line. In find I coulnd't write each file by hand ...
i've got another command awk '{ print FILENAME, $0 }' (it claims to show the filename though it shows it didn't end
Currently I blame the Linux learning curve because of google results and non-answered messages and all that after translation if a nice question directly to English. Isn't that it hard to make more help to design unixes language in that way to be really descriptive and write it as you think.
I'm deeply sorry for that grief!...(
Moderator's Comments:
edit by bakunin: please use CODE-tags for code, as required by the forum rules and refrain from excessive formatting. How is text in one-point size in light cyan against a white background supposed to be read?
Last edited by rbatte1; 02-25-2015 at 06:49 AM..
Reason: Added some ICODE tags too
I will try to answer your question but let us start with the biggest problem of them all, in my opinion: your attitude.
Quote:
Originally Posted by Xcislav
Currently I blame the Linux learning curve because of google results and non-answered messages and all that after translation if a nice question directly to English. Isn't that it hard to make more help to design unixes language in that way to be really descriptive and write it as you think.
I'm deeply sorry for that grief!...(
What i see is inability to analyse or even describe a problem succinctly. For instance:
Quote:
Originally Posted by Xcislav
could I output a list of five books with their filename titles into one file?
What do you mean by "books"? UNIX (or Linux) does not deal with "books", only with files, filenames, directories, etc.. So how does the term "book" map to:
Quote:
Originally Posted by Xcislav
In order o output all the contents of all the files with their filenames there was
I am already confused. What is "book"? A filename? A part of a filename? A files content? Something else?
Quote:
Originally Posted by Xcislav
Save for the fact that you should indeed use CODE-tags this is clearly nonsense. Either you should use the "xargs" command and pipe the output of "find" to that or use "find"s built-in "-exec" to do these things:
Note, i used ">>" (append) instead of ">" (overwrite) because otherwise each new file content will wipe out the former one which i suppose you do not want. Also note that you are searching for files and write a file at the same time. Depending on circumstances your output file will be included in "find"s output or not and you should do it in a way where you do not take that chance:
Quote:
Originally Posted by Xcislav
In spite of them being successively named 1Atitle... 2Atitle the two first aren't 1A 2A, but 1A ..5A (2 3 4) They actually are: 1АБетховен.. 5АБетховен... It now breaks all things I hoped.
OK, by now i think i have successfully guessed what what you mean: You want the file names (=titles?) to be ordered alphabetically. Use the command "sort" to achieve this. Compare the output of these two commands:
Note, though, that "sort" is influenced by your LOCALE setting. From the few interspersed cyrillic characters i deduce your language setting is not english.
Quote:
Originally Posted by Xcislav
Could the task be done by head, cat or grep command? Cat has no filename parameter, head can't output the whole file and grep has a filename parameter but it's primary use is searching one line. In find I coulnd't write each file by hand
I admit i am confused again. "cat" has indeed a filename parameter (which you already used in your command), your "task" is nowhere described so if "cat", "head", "grep" or some other command is suited to do it we cannot know and although i thought i guessed what you want i now think my guess was wrong. How about describing it instead of letting me exert my psychic talents?
Quote:
Originally Posted by Xcislav
i've got another command awk '{ print FILENAME, $0 }' (it claims to show the filename though it shows it didn't end
I think that this could be shortened and performance improved by only opening the output file once for a write:-
The braces { & } allows you to handle all the output in one block, so it can be written in a single operation far more efficiently than the multiple open-write-close processes of appending within a loop. The echo and the touch seem irrelevant to me, so I've left them out.
Just my thoughts,
Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
Hi everyone :)
I have a file "words.txt" containing hundreds of lines of text. Each line contains a slogan.
Using the code below i am able to generate an image with the slogan text from each line.
The image filename is saved matching the last word on each line.
Example:
Line 1: We do... (2 Replies)
Hello,
I am trying to print searched multiple keywords in multiple files.
It is almost okay with the code but the code puts filename in front of each line.
How may I get rid of it?
-grep -A1 'word1' *.txt | grep -A1 'word2' | grep -A1 'word3'
I expect:
Real outcome:
How may I... (3 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
A) Write a script, which will take input from a file and convert the number from Centigrade to Fahrenheit... (5 Replies)
Issue: I am able to split source file in multiple files of 10 rows each but unable to get the required outputfile name. please advise.
Details:
input = A.txt having 44 rows
required output = A_001.txt , A_002.txt and so on. Can below awk be modified to give required result
current... (19 Replies)
Hi Friends,
I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving...
File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Hey, guys, scripting newb here. I'm trying to get a list of all .dmg files in a folder and save the output into an array. My first attempt was
ARRAY= ( `ls $REIMAGEPATH | grep \.dmg$` )
However, I understand why that doesn't work now (at least I think I do).
But I don't know what the... (5 Replies)
I know this is a simple matter, but I'm new to this.
I have a shell script that calls a sed script from within it. I want the output of the shell script to be based on the input file I pass as an argument to the original script. In other words...
./script.sh file.txt
(script.sh calls sed... (2 Replies)
A frequently asked question (on this forum and others) is what Solaris books are available. The quality of such books can range from downright awful to "bible-like" textbook. There are sysadmin books, kernel design books, all-in-one references and Sun certification exam books. I've put together a... (0 Replies)
Hi all,
I have a list of xml file. I need to split the files to a different files when see the <ko> tag.
The list of filename are
B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml
B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml
B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml
... (3 Replies)
I have another question. I have access to the books listed below, however I know that not all of them are the lates and greatest and some are over 10 years old. So the question is are most of these books still a good idea to read. Or should I try and pick up the latest and greatest editions?
... (5 Replies)