Putting echo output as input to stat


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Putting echo output as input to stat
# 1  
Old 08-10-2010
Putting echo output as input to stat

I have a string with escape differentiators as a result of searching for a file using find. Essentially find returned to my shell variable several absolute paths each ending with the file name and each path/file separated by \n.

Echo recognizes the escape sequence and is able to print the paths to the screen. I tried to instead send the full escape sequence string form echo into stat but I was propmpty suggested to try --help.

This is what I tried:

Code:
echo $file_path | stat -c %F

I need a filename or something don't I?
# 2  
Old 08-10-2010
Most well-written unix utilities accept stdin as a valid input usually like this
Code:
echo "thing" | command -

The trailing - means 'read from stdin'

Unfortunately the stat command line utility does not do this, at least the one from coreutils3.3 does not. Try it if you have a newer version.
# 3  
Old 08-10-2010
xargs can understand find's output pretty much natively, and run a command you specify. No need to convert the newlines into escape sequences and back.
Code:
find -print0 /path/to/files | xargs --null stat -c %F

# 4  
Old 08-10-2010
Quote:
Originally Posted by Corona688
xargs can understand find's output pretty much natively, and run a command you specify. No need to convert the newlines into escape sequences and back.
Code:
find -print0 /path/to/files | xargs --null stat -c %F


Corona, and those replying, I appreciate the assistance. Xargs is a utility that I will keep in my back pocket from now on. I used it successfully as follows:

Code:
 find / -name "$file_name" -print0 2> /dev/null | xargs --null stat -c %F

This small piece of code allows me to acquire the file type inode info on any number of files
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

2. UNIX for Dummies Questions & Answers

Auto input with echo

in cygwin, cron-config will ask two inputs: yes or no. 1st question, answer is no 2nd question, answer is yes my script: echo no | cron-config how do i pass yes to 2nd question ? (4 Replies)
Discussion started by: lawsongeek
4 Replies

3. UNIX for Dummies Questions & Answers

stat output

hi guys i got confused about stat output stat manual says File : Size in Bytes Blocks : Number of blocks used IO Block : Size in bytes of every block. when i use stat command for passwd file it says ~#stat /etc/passwd File: `/etc/passwd' Size: 999 Blocks: 8 IO... (4 Replies)
Discussion started by: mhs
4 Replies

4. Shell Programming and Scripting

Need help putting output on one line

Good afternoon, I have been searching the web, and these forums for help. I will try my best to explain the issue, and what my desired results are. I am doing queries in MYSQL, and need the output to be sent to a file. That file needs to have things with the same ID on the same line. To... (14 Replies)
Discussion started by: brianjb
14 Replies

5. Shell Programming and Scripting

accept input on an echo output

echo (some info) read? <&1(not working for me) (1 Reply)
Discussion started by: robin_simple
1 Replies

6. UNIX for Dummies Questions & Answers

Putting the Current -date in the Output File

Hi guys, Just want to ask how can I make a script that will perform like this. 1. Execute the command 2. Then the output of the command will be redirected to a file 2. The file that has been created will have a date on it equivalent to the date and time it was created (or maybe after the... (5 Replies)
Discussion started by: rymnd_12345
5 Replies

7. Shell Programming and Scripting

putting color on output file script

do you have any simple script on how to change the color and font of a string in a script example echo "====================================" echo " sample color script" echo "====================================" echo " hello " echo " bye" on hello,... (3 Replies)
Discussion started by: lhareigh890
3 Replies

8. Shell Programming and Scripting

How to redirect the output to multiple files without putting on console

How to redirect the output to multiple files without putting on console I tried tee but it writes to STDOUT , which I do not want. Test.sh ------------------ #!/bin/ksh echo "Hello " tee -a file1 file2 ---------------------------- $>./Test.sh $> Expected output: -------------------... (2 Replies)
Discussion started by: prashant43
2 Replies

9. Shell Programming and Scripting

Getting command output and putting into newfile

Hello All, I am using the below code: #!/bin/sh /omp/bin/TICLI "op:alarm,all" > filename for getting command output and then putting the output into newfile but the problem is this, that not the complete output goes into newfile and the script stops. for example: if this commands gives... (18 Replies)
Discussion started by: wakhan
18 Replies

10. Shell Programming and Scripting

Putting screen output in a log file

I want to output screen messages to a logfile when executing an automated script. I have tried the script and command to do this but with no luck. Thanks, Nicole (5 Replies)
Discussion started by: nsutti
5 Replies
Login or Register to Ask a Question