I use the following command to convert my input file contents to lowercase  tr A-Z a-z &lt; input &gt; output    This command works fine.  But when I try to store the output in input file itself, it is not working. The input file is empty after executing the command. Why?   tr A-Z a-z &lt; input &gt; input
19823
Possible Duplicate:          I frequently connect to amazon ec2 using their public DNS names (ec2-12-34-56-78.compute-1.amazonaws.com) and because of this my known_hosts file gets overwhelmed with a lot of ec2 entries I will never use again.  I know I could probably use sed -i to edit in place but I wanted to use grep and so I did this:  grep -v ec2 ~/.ssh/known_hosts &gt; ~/.ssh/known_hosts   That leaves known_hosts as an empty file. If I do:  grep -v ec2 ~/.ssh/known_hosts &gt; ~/.ssh/tmp mv ~/.ssh/tmp ~/.ssh/known_hosts   then things are fine, but I am confused why reading and writing to the same file leaves it blank, and if there is any way around this when using grep, cat, etc.
91670
I have a txt file like this John Doe;john Doe is ...;he lives in ... Mike Nelson;mike Nelson works for ...;he makes ... Marcy William;marcy's mother is ...;marcy travels a lot...   I want to convert every character following a semicolon to uppercase, so the final result is John Doe;John Doe is ...;He lives in ... Mike Nelson;Mike Nelson works for ...;He makes ... Marcy William;Marcy's mother is ...;Marcy travels a lot...  keeping the rest intact. This file contains accented letters and is coded in UTF-8. How do I do that using sed, awk or whatever using terminal? Thanks
62288
This question was prompted by questions about ls' -1 option and the recurring tendency of people to ask question and answers that includes processing the output of ls.   This reuse of the output ls seems understandable, e.g.: if you know how to sort a list of files with ls you might want to use the output in that way as input for something else.  If those Q&amp;A don't include a reference to the file name list produced consisting of nicely behaving file names (no special characters like spaces and newlines), they are often commented upon by someone pointing out the danger of the command sequence not working when there are files with newlines, spaces etc.  find, sort and other utilities solve the problem of communicating "difficult" file names to e.g. xargs by using an option to separate the file names with the NUL character/byte which is not a valid character in file name (the only one in addition to /?) on Unix/Linux filesystems.  I looked to the man page for ls and the output for ls --help (which has more options listed) and could not find that ls (from coreutils) has an option to specify NUL separated output. It does have a -1 option which can be interpreted as "output file names separated by newline")  Q: Is there are technical or philosophical reason why ls does not have a --zero or -0 option that would "output file names separated by NUL"?  If you do something that only outputs the file names (and not use e.g. -l) that could make sense:  ls -rt -0 | xargs -r0 …   I could be missing something why this would not work, or is there an alternative for this example that I overlooked and that is not much more complicated and/or obscure.    Addendum:  Doing ls -lrt -0 probably does not make much sense, but in the same way that find . -ls -print0 does not, so that is not a reason to not provide a -0/-z/--zero option.
32551
My input file is,  ami21 ami65 ami67 ami66 ami88 ami76 ami29 ami55  ami54 ami32   Using a single command line I need the output as,  ami22 ami66 ami68 ami67 ami89 ami77 ami30 ami56 ami55 ami33   I used the command  awk -vRS=ami '{$0=$0+1;ORS=RT}++n' inputfile &gt; outputfile   but I got the outputfile as ami21ami65ami67ami66ami88ami76ami29ami55ami54ami32  i.e. all strings are written in same line and without space. Could anyone suggext me some better command line.
41507
I have simple text file named "example".  Reading with terminal command: cat example  Output:  abc cdef ghi jk lmnopq rst uv wxyz   I want to convert (transform) into following form: (expected output from cat example)  abc cdef ghi jk lmnopq rst uv wxyz   How can I do this via the command-line?   (This is only an example file, I want to convert word's position in vertical-column)
113284
I have a file called -.  I want to display its contents.  One way is to do  cat ./-   since cat - reads from standard input. However, why are cat "-" and cat '-' also interpreted by the shell as cat -?
79722
My goal is to output an html source into a file, I'm using w3m to browse the web from terminal.  When using the following command on terminal: w3m &lt;url&gt; -dump the program displays the web site in a non interactive way, but no its html source.  If you open a web site with w3m &lt;url&gt;, the terminal will display the site and if you press v, then the program will display the html source, I tried to script this but with no success. I thought the command line argument -dump_source would help me, but the only thing I got is a non-human reading content, I don't know what -dump_source was supposed to return  Here is what I tried so far:   Use -T text/html with -dump on terminal but the output didn't changed Use -T text/plain with -dump_source on terminal hoping that the non-human output would be converted to a plain text, but no success (I didn't understand what -T is used for, even after reading w3m manual by typing man w3m on terminal) Knowing that pressing v while w3m is displaying a web site switch from web page content to html source code, I tried to use gdb to attach it to the w3m process and redirect its stdin and stdout to my files (input.txt, output.txt) which input.txt contains a single v, but I had no success. Doing this on my test program worked as expected. I followed what was described . If I write ls -l /proc/&lt;w3m_pid&gt;/fd, where w3m_pid is my w3m process id which I got by using ps ax on terminal, I can see there is 3 file descriptors, if I try to redirect the third one, the program crashes and displays: Error occured: errorno=25 Redirecting the standard I/O with w3m &lt;url&gt; &lt; input.txt &gt; output.txt also did not worked W3M uses keybinding to navigate on the web, it means that if you press v there is no need to hit enter, the terminal is not buffering the input, using gdb attached to the w3m process I tried to remove it by using p system ("/bin/stty cooked"), but the w3m keybind did not changed.   My question is: why redirecting I/O with gdb is not working and what I can do to get html source code? w3m have an option to output html source code that I'm missing or I would have to use another program?  PS: I need html source code for a university homework, with html source code I can create a script to browse the web and output the page into a file, than I'm supposed to use those outputs with flex to extract statics information about things on the web, like: how many the word stack appears in questions about the c language? This is my idea.  Any suggestions would be appreciated.  W3M version: 0.5.3+debian-15  GDB version: 7.7.1   Ubuntu version: 14.04  Thanks in advance!
50062
I've got a script 'myscript' that outputs the following:  abc def ghi   in another script, I call:  declare RESULT=$(./myscript)   and $RESULT gets the value  abc def ghi   Is there a way to store the result either with the newlines, or with '\n' character so I can output it with 'echo -e'?
89325
How do I clear the contents of a file before writing to it? For example:  echo one &gt; filename.tmp # filename.tmp now contains "one"  echo two &gt; filename.tmp # filename.tmp should now contain "two", not "one" and "two"   My goal is:   Start a listener  $ nc -l 7007 &gt; /var/tmp/test.log  Send some data  $ telnet localhost 7007 hi second_word  Test the file  $ cat /var/tmp/test.log second_word    I don't want "hi" to show up in the log; I want "second_word" to have replaced it
57883
I've just come across the &lt;&lt; command, used like so:  cat &gt; outfile.txt &lt;&lt;EOF Multi-line content that will be written to outfile.txt EOF   Now, I've no idea what this is called, but I'd quite like to know it's name, primarily so I can go and search and find out more about its syntax. Sadly, Googling for "&lt;&lt;" just doesn't work.
73988
Everybody knows :-) that in Windows plain text files lines are terminated with CR+LF, and in Unix&amp;Linux - with LF only. How can I quickly convert all my source code files from one format to another and back?
62738
Let's say I compile the following file with pdflatex -shell-escape test.tex:   \documentclass{minimal}  \begin{document}  File listing is:  \immediate\write18{ls /usr}  \end{document}   This will send the output of the command ls /usr to report/log of pdflatex (primarily to stdout).   There are then two cases I'd like to utilize:    The output of ls /usr being included directly in the document (LaTeX stream). The output of ls /usr becoming the contents of a \newcommand (by this I mean, that I'd like the script to be executed when the \newcommand is executed first - and upon subsequent calls to the new command, the shell code should not be executed anew).    I have read through , but I'm not sure if this "pipe input" can be applied to \newcommand.   I have also read through  - and it seems that Tex' file I/O should be used; but I'm quite disliking the fact that I'd still have to redirect the script output (actually, in this case, the ls /usr output) to a file, and then read it in, to have it as contents of a command.   So, is there an easier way to achieve what I'd want (hopefully, illustrated through an example based on the above code)?     EDIT: Ehm, I should have asked one more question earlier :) I'll try with an edit here, although it will probably get missed .. :)   I originally asked for a \newcommand that will execute shell code only upon its definition (i.e., in a sense it is "cached"); and the answer from @egreg does exactly that. But then - would it be possible to have a different \newcommand definition, such that each time this newcommand is called, the shell command is executed anew? I.e. executing something like \@@input|"cat tempfile" (which cannot be executed as such), where tempfile changes between calls?
41971
I have a bash script which enumerates through every *.php file in a directory and applies iconv to it. This gets output in STDOUT.   Since adding the -o parameter ( in my experience ) actually writes a blank file probably before the conversion takes place, how can I adjust my script so it does the conversion, then overwrites the input file?  for file in *.php do     iconv -f cp1251 -t utf8 "$file" done
67894
Can I write the output of the time difference command to a file?  For example, I tried:  $ time foo.sh &gt; bar.txt   But it only gives the output of foo.sh to bar.txt.
56422
When I use less at the command line the output is like   but when I use less from within a bash script I get:   How can I use less in a bash script and not get all the escape characters and have it work like it does at the interactive command line?
101077
Is there any short way to save the pipe output to the same file that it's processed. For example, this is what I am actually doing  $ cat filename | sort | uniq &gt; result $ rm -f filename $ mv result filename   I was wondering if there was a way to do it in just one line (not appending those commands using &amp;&amp;)  This is not the way, but to get an idea  $ cat filename | sort | uniq &gt; filename
3824
How do I save the output of a command to a file?  Is there a way without using any software? I would like to know how.