Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I made a copy of all the backups made on Wed of every week The time stamp of each file is not sorted but the day is Wednesday of every file

Now, I need to sort each file based on time Stamp e.g if date is 1-May then it should first display the backup files of 1-May then it should display the files of 8-May

I used this command but of course it is slapping me with error

sort $(cat /home/emerg/Wedbackup.txt)

Error is

sort: invalid option -- w

As i don't know how to use the output of one command as input of 2nd command. I need advice how to do it.

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

There's no need to use cat in this case:

sort /home/emerg/Wedbackup.txt

The problem with your example is that your file is being passed as the command line to sort, which is not what you want. For example, if this was your file:

foo bar
baz qux
wibble wobble

The arguments would look like this:

sort foo bar baz qux wibble wobble

This is not what you want. What you actually want is to pass the file to sort on stdin, which can be done like this:

sort < /home/emerg/Wedbackup.txt

This is more generalisable, as taking a filename as an argument is specific to sort, and is not a universal convention.

In the case of sort, you should prefer to pass the filename as an argument rather than on stdin, as it allows seeking on the file, which can improve sorting efficiency.

share|improve this answer
add comment

You should use pipe, like this:

cat /home/emerg/Wedbackup.txt | sort
share|improve this answer
    
UUOC –  l0b0 May 13 '13 at 13:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.