Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
When I am using the cut command in linux, and redirecting the output to the same file, it seems to delete the contents of my file. What I am doing is:
cut -d " " -f 1 file1.txt > file1.txt
My goal is to cut out all columns from the file, except for the first column and save changes to the file that I am working with. But when I do this, and open my file, I am left with a blank file. However, when I specify a different file, the command seems to work perfectly fine.
When I run:
cut {some command} FILE1.txt > FILE2.txt
This seems to work fine.
Is there a way that I can specify that I want the changes from my cut command to be overwritten on to my current working file?
Create a temporary file with the desired changes and then rename it to the target file name:
cut -d " " -f 1 file1.txt > file1.txt.temp
mv file1.txt.temp file1.txt
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I'm trying to enter input without typing anything I'm trying to put the input in the command.
I've seen people try this:
printf 'argument\n' | command
Or
command <<< "argument\n"
I don't know if what I'm doing is command specific but neither of these work for what I'm trying to do.
I'm trying to zip a file with a password:
zip -r -e test.zip test_zip/
-e is for password input (this isn't the part I was talking). I set the password to test1234.
When I unzip the file I try things like this:
printf 'test1234\n' | unzip test.zip
But it still asks for password input.
Any suggestions?
If you are using the Linux command line, try using echo.
echo 'test1234' | unzip test.zip
Use the -P argument
unzip -P <password> <zipfile>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
Experts
I'm trying to send two files in a single sftp command line. right at the moment, I can only send 1 file when using the command line.
sftp host file1
but I'm looking for
sftp host file1 file2
I have to do that on 4 differents servers every day with different username.
Thanks
If you know what files exactly you want to send, you should use the scp utility. It can do just what you want.
scp file1 file2 .... user#host:/path/to/folder
Thanks to Neil for remembering the ":/path/to/folder" bit
To do it with different usernames you could probably script it. Something along the lines of:
#!/bin/bash
scp "$#" user1#host
scp "$#" user2#host
scp "$#" user3#host
scp "$#" user4#host
usage: ./myscript.sh file1 file2 ... filen
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
anyone help what this command does as I do it with a single > and it creates a new file when I do ls > list, but I can see nothing when I do ls >> list
As already mentioned, > overwrites while >> appends.
Now for the query that you have,
You first executed ls > list, created a file named list.
Then, you executed ls >> list, which appended the result of ls command to your existing file. You can see the changes only if you open the file.
Try the following:
Remove the existing list file: rm -f list
Execute ls >> list, this will create the file list.
Execute ls > list, this will overwrite the contents of the file list.
Remember:
> and >> will both create the file if it does not exist.
Consequent executions of > on existing file will overwrite the file, while that of >> will append the output to the file.
In any case, you will be able to see the change only when you open the file after > or >> operation.
> is used to redirect the standard output to a file. (command > output file)
If file exist it will replace it. If you want to append, use >>instead.
So if you do ls > file, then file will content the files in your directory (id est output of the ls command)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have many files named xxxx.min.js and want to rename the files to xxxx.js so basically want to remove .min only.
Is there a command I can use to do this job?
I thought using rename command would be easy for each single file, but that would take forever since I have many of them.
any idea?
Here's a bash-only command (not requiring Perl)
for i in *.min.js; do a=$(basename $i .min.js); echo mv $i $a.js; done
Explanation
for i in *.min.js; do
loop over all files matching *.min.js
a=$(basename $i .min.js)
extract the base name of the file (i.e. strip off .min.js) and save the result in $a
echo mv $i $a.js
for now, print to the console the command that WOULD be run if you removed the echo
When you are satisfied that it generates the correct commands, remove the echo to actually rename the files.
Ubuntu and Debian linux distribution both have a perl version of mv function called rename or prename, which supports regexp. The manual can be found here.
Go to the folder of the files and run the command as follows:
rename s/\.min\.js$/\.js/ *.min.js
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
So I am trying to use
grep -v -f A.txt B.txt
to display lines NOT included in file A but present in file B. When I
grep -f A.txt B.txt
everything works fine I receive output with correct lines highlighted, but when I use
grep -v -f A.txt B.txt
nothing is outputted in spite of the fact that not all lines match patterns. Does anyone knows why? I am interested in seeing lines NOT present in file A.
Note: I am including just a sample of original file but it includes all troublesome lines.
file B.txt contents:
/lgi/tch/4337984048.html
/mnh/tch/4337954734.html
/fct/tch/4337745272.html
/brk/tch/4337711890.html
/mnh/tch/4337530587.html
/mnh/tch/4337480118.html
/mnh/tch/4337393833.html
/wch/tch/4337280071.html
/wch/tch/4337105236.html
/brk/tch/4337068170.html
file A.txt contents:
/mnh/tch/4337480118.html
/mnh/tch/4337393833.html
/wch/tch/4337280071.html
/wch/tch/4337105236.html
/brk/tch/4337068170.html