LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-15-2015, 09:59 PM   #16
cfajohnson
LQ Newbie
 
Registered: Aug 2012
Distribution: Linux Mint 17
Posts: 22

Rep: Reputation: Disabled

Quote:
Originally Posted by evo2 View Post
There's no *need* for printf either. Assuming the OP is using bash, printf is not a shell builtin, a new process is spawned either way. Indeed there are many way to get that output, feel free to post as many of them as you like.
printf is a builtin command in bash, ksh, dash; tr is an external command (many, many times slower).
 
Old 01-15-2015, 11:31 PM   #17
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

ok, I stand corrected. I know printf is a zsh builtin, but didn't know it was in bash.

Evo2.
 
Old 01-16-2015, 06:31 AM   #18
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by evo2 View Post
Hi,

If using the sort command from coreutils you can use the -V option to get the desired results without leading zeros.

Evo2.
Missed that one. It should work quite well.
 
Old 01-16-2015, 01:30 PM   #19
atjurhs
Member
 
Registered: Aug 2012
Posts: 307

Original Poster
Rep: Reputation: Disabled
hi guys,

i didn't create the files or the directories somebody else did, so i can't pad them without running some other commands that i don't know.

what's the difference in these two?

Code:
find . -name '*.dat' -exec cat */*.dat > out.txt
Code:
find . -name '*.dat' -exec cat dir*/*.dat > "$file"
tabby
 
Old 01-16-2015, 04:31 PM   #20
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Both are incorrect - in the same way.

find will locate the file that matches the -name pattern - then the cat will find all files that match the pattern "dir*/*.dat" - for EACH file that matches the -name pattern.

You want to use the file that find found, you replace the "cat dir*/*.dat" with "cat '{}'" which will execute cat only once for each file.

The major problem is that find will use whatever order the files were added to the given directory - and that may not be the order you want them in.
 
Old 01-16-2015, 05:12 PM   #21
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Both are incorrect in that the cat command is completely ignoring whatever find located. All you will get from either one is, "find: missing argument to `-exec'" and an empty output file.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Oops, cat iso file to wrong device drivekiller361 Linux - General 21 01-02-2015 02:43 PM
[SOLVED] MBR, GRUB and Partitions messed up : Partition table entries are not in disk order fabien Linux - Laptop and Netbook 6 04-12-2012 01:37 PM
[SOLVED] concat files in numerical order using cat and sort DEF. Programming 16 01-27-2010 02:53 PM
cat safely without messed up terminal curos Slackware 6 08-20-2006 01:54 PM
logrotate log files - keeping in order when using grep or cat and bash dmellem Linux - Software 6 02-11-2005 01:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration