ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
In bash > is the redirect operator. It will put the output of the command into the file with that name. So you put first what you would want to end in the file (pkg_version and the grep) and then redirect the output to the file named in the specific way.
Last edited by vladmihaisima; 02-14-2009 at 02:08 PM.
Reason: (added more detailed explanation)
the > will send the output of the previous command to the filename specified, creating a new file if needed, or overwriting the file contents if it already exists. If you want to append the new data to an existing file instead, use >>.
Edit: Hah...beaten to the punch again.
Last edited by David the H.; 02-14-2009 at 02:12 PM.
I tryed pkg_version |grep "<" > touch filename`date +-%d-%m-%Y` before, just forgot to post it.... tryed with > and >>, then inverted the comand and tryed < and <<, but still, doesn't work. I get (with pkg_version [...] >> touch [...]) grep: filename-actual-date-here: No such file or dir.
one more thing.... the file the output will be dumped to doens not exist, has to/will be created prior to the actual comand
Code:
[da1@da1.ro ~]# pkg_version |grep "<" >> touch filename`date +-%d-%m-%Y`
grep: filename-14-02-2009: No such file or directory
[da1@da1.ro ~]# pkg_version | grep "<" > touch filename`date +-%d-%m-%Y`
grep: filename-14-02-2009: No such file or directory
[da1@da1.ro ~]# touch filename`date +-%d-%m-%Y` << pkg_version |grep "<"
? <- remains stuck here, unles i do ^C
and
Code:
[da1@da1.ro ~]# touch filename`date +-%d-%m-%Y` < `pkg_version`
^C
^C
^C
^D
^C
^X <- stuck, whatever I do. Have to terminate user session to get back shell
happens with `pkg_version` and pkg_version after <
Well, single quotes prevent any substitution by the shell. If you want a special character to be interpreted literally you have to embed in single quotes, whereas double quotes still permit some substitutions.
Anyway, I think that actually the error was the touch command. In your command line
the grep command look for the pattern "<" in the standard input, redirect the output to a file called touch and look for the pattern in the non-existent file filename-14022009. Hence the grep error.
Another tip: if you want the files with date in their name to be sorted in alphanumeric order AND by date when listed, use the format %Y%m%d.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.