Author Topic: Output a list of five books with their filename titles into one file  (Read 1557 times)

0 Members and 1 Guest are viewing this topic.

Offline xcislav

  • Jr. Member
  • **
  • Posts: 4
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Dear forum of Linux,
could I output a list of five books with their filename titles into one file?
In order o output all the contents of all the files with their filenames there was: 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 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'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!...(

Offline chemicalfan

  • Hero Member
  • *****
  • Posts: 1166
  • Karma: 36
  • Gender: Male
  • I've been here a little while!
    • View Profile
    • Awards
Re: Output a list of five books with their filename titles into one file
« Reply #1 on: February 25, 2015, 10:07:57 am »
*shrug*

bash is easier than csh, think yourself lucky! You could try using Python, the syntax is easier but it's a lot more complicated to interact with the filesystem. I think a lot of the complexity comes from "regular expression syntax", but that's universal - you've just gotta live with it.

Sidenote - is this homework?

Offline Mark Greaves (PCNetSpec)

  • Hero Member
  • *****
  • Posts: 18277
  • Karma: 477
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
Re: Output a list of five books with their filename titles into one file
« Reply #2 on: February 25, 2015, 11:54:16 am »
If I'm understanding you correctly (and I'm probably not) .. how about:
Code: [Select]
find . -type f -printf "\n--> %f <--\n" -exec cat {} \; > ~/бетховен.txt
(do not output to the same directory you're running find in)
« Last Edit: February 25, 2015, 12:03:58 pm by Mark Greaves (PCNetSpec) »
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal