Output a list of five books with their filename titles into one file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Output a list of five books with their filename titles into one file
# 1  
Old 02-25-2015
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:
Code:
find . -type f | while read x; echo -e "\n$x";cat "$x";done > бетховен.txt

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 Smilie ...

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:
Mod Comment 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
# 2  
Old 02-25-2015
Hi
Hope i understand you correct:
Code:
touch outfile
echo "" > outfile
while read book
do 	echo "$book" >> outfile
	cat "$book" >> outfile
done<infile

hth

Last edited by sea; 02-25-2015 at 04:35 AM..
# 3  
Old 02-25-2015
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
Code:
find . -type f | while read x; echo -e "\n$x";cat "$x";done > бетховен.txt

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:

Code:
find . -type f -exec cat {} >> бетховен.txt \;

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:

Code:
find . -type f -exec cat {} >> /some/where/else/бетховен.txt \;

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:

Code:
find . -type f
find . -type f | sort

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
что ?? Could you please explain what you mean?

I hope this helps.

bakunin

Last edited by bakunin; 02-25-2015 at 04:47 AM..
# 4  
Old 02-25-2015
Quote:
Originally Posted by sea
Hi
Hope i understand you correct:
Code:
touch outfile
echo "" > outfile
while read book
do 	echo "$book" >> outfile
	cat "$book" >> outfile
done<infile

hth
I think that this could be shortened and performance improved by only opening the output file once for a write:-
Code:
{ while read book
do
   echo "$$book"
   cat "$book"
done < infile } > outfile

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:
# 5  
Old 02-25-2015
Robin, you got a typo @
Code:
echo "$$book"

# 6  
Old 02-25-2015
I am a fool Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Insert the line number from text file to filename output

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)
Discussion started by: martinsmith
2 Replies

2. Shell Programming and Scripting

How to remove filename from output file?

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)
Discussion started by: baris35
3 Replies

3. Homework & Coursework Questions

Loop to Convert a list from an input file and output it to another file

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)
Discussion started by: AliTheSnake
5 Replies

4. Shell Programming and Scripting

File Splitter output filename

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)
Discussion started by: santosh2k2
19 Replies

5. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

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)
Discussion started by: asnandhakumar
6 Replies

6. Shell Programming and Scripting

Output file list to array?

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)
Discussion started by: nextyoyoma
5 Replies

7. Shell Programming and Scripting

use input filename as an argument to name output file

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)
Discussion started by: estebandido
2 Replies

8. Solaris

A List of Solaris Books

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)
Discussion started by: DraconianTimes
0 Replies

9. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

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)
Discussion started by: natalie23
3 Replies

10. UNIX for Dummies Questions & Answers

list of books I have access to

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)
Discussion started by: bru
5 Replies
Login or Register to Ask a Question