How do I copy grep output to another text file in different directory? [closed] - linux

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 days ago.
Improve this question
I am trying to copy specific words from a text file in a directory to another using grep. I have the retrieval of the words I want from the text file, now I just am wondering how I would go about moving it another text file, say in my home directory.
Here is the grep command.
grep -E '^.[*ing]{5}$' words
and here is what I have tried
grep -E '^.[*ing]{5}$' words > words.txt $home
grep -E '^.[*ing]{5}$' words > words.txt /home/
Any help is appreciated!

grep -E '^.[*ing]{5}$' words > /home/words.txt

Related

What do terminal commands ls > wc and ls | wc show? [closed]

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 know what the commands ls and wc do, but I can not find out what ls > wc and ls | wc will show. Can someone please help me flush out the meaning of this commands?
ls | wc The output from the ls command is piped into the wc command. So it will count the words which are in the output of ls. So you see simply the number of files read by ls.
ls > wc This creates a new file in your current working directory with the name wc with the output of your ls command. The program wc is not used here, simply a new file with the same name is created. You can simply look into this new file with your favorite editor or simply use cat for it.

With cat command create a file which is a merge of 2 files(linux) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
What I'm trying to do:
With cat command create a file named Merge which is the merge of
test.txt and Copy(in a different directory than test.txt)
Both test.txt and Copy contain the same content:
reglib
test.txt
So what I expect is:
reglib
test.txt
reglib
test.txt
What I've tried:
cat /home/eleve/Copy | cat test.txt >Merge.txt
cat /home/eleve/Copy >Merge.txt | cat test.txt >Merge.txt
cat /home/eleve/Copy >Merge.txt | cat test.txt >>Merge.txt
And all of those command gave me the same wrong result:
reglib
test.txt
Can anyone please suggest me the right command? thanks.
You can use "cat" on multiple files, in which case it'll print them out in order.
cat test.txt Copy

Inverted grep search with a pattern file? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm using grep with an inverted search (-v) to remove lines from a user file that I don't want to keep. As the pattern changes, I want to use a pattern file to grab the pattern that needs to be removed. However, it's failing and I don't know why.
This works perfectly:
grep -v -F 'removethisstring' inputfile > newfile
newfile is correct, the pattern line is now removed from the file.
However, putting the pattern in a file it fails:
grep -v -F -f patternfile inputfile > newfile
newfile is unchanged, the line with the pattern is still there. What am I doing wrong?
inputfile
grapes are purple
hello fox in the house
bonnet is blue
simple is best
patternfile
fox
newfile result:
(same as inputfile)
desired output
grapes are purple
bonnet is blue
simple is best
Try running dos2unix on patternfile before using to remove control M characters and check.

Rename large number of files in bash [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a large list of files that I want to rename.
Much like this
So this is what my files look like
something.pcap1
something.pcap10
something.pcap11
something.pcap12
...
something.pcap111
something.pcap1111
essentially I want to rename all of the files so that the numbers get padded with 0's and they are 5 digit numbers.
something.pcap00001
A simple for loop should do the trick (can be script file):
for file in $(ls -1 something.pcap*); do
[[ ${file} =~ ^something.pcap([[:digit:]]*).* ]]
newfile=$(printf "something.pcap%05d" ${BASH_REMATCH[1]})
mv ${file} ${newfile}
done
Something like this?
rename 's/\d+$/sprintf("%05d",$&)/e' soemthing.pcap*
Note: this works with the rename as found in debian and its derivates.
What about something like this?
#!/bin/bash
for i in $(ls something.pcap*); do
q=$(echo $i|sed -e 's/pcap/pcap00000/;s/pcap0*\([0-9]\{6,\}\)$/pcap\1/')
mv $i $q
done
I hope this will help

Appending the contents of a file at the beginning of another file in UNIX [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
The community reviewed whether to reopen this question last year and left it closed:
Not suitable for this site 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.
Improve this question
I know that
cat file1 >> file2
would append the contents of file1 at the end of file2. On the other hand, how can I append the contents of file1 at the beginning of file 2, and not at its end?
Actually, i have a single master file M, and several other files in a directory D. I want to append the contents of file M at the beginning of all the files in the directory D.
Just do:
cat file1 file2 > tmp && mv tmp file2
For each file you could do:
cat MASTER file >> file.tmp
And then move file.tmp over file.
You will have to use a temporary file and rename it after merge.
Example:
echo -e "a\nb\nc" > LETTERS
echo -e "1\n2\n3" > NUMBERS
cat NUMBERS LETTERS > TMP
mv TMP LETTERS
cat LETTERS
Your command might look something like:
for file in $( find -name "*.java" ); do cat PREPEND ${file} > ${file}.tmp; mv ${file}.tmp ${file}; done

Resources