Copy lines containing a specific text from one file to another file
You can just change your command in the following way and it will work:
awk '/Cmd:\[41\]/' file1.txt > file2.txt
Explanations:
'/Cmd:[41]/'
will match lines that contain: Cmd:4
or Cmd:1
but will not match lines that contain literally Cmd:[41]
as [...]
are used in regex to define a character range, or a list of characters that can be matched therefore you need to escape them by adding a \
before them.
How do I copy lines next to line of another file in Linux?
Linux has paste command. Basic example is as follows.
paste file1 file2 > file3
How to find words from one file in another file?
You can use grep -f
:
grep -Ff "first-file" "second-file"
OR else to match full words:
grep -w -Ff "first-file" "second-file"
UPDATE: As per the comments:
awk 'FNR==NR{a[$1]; next} ($1 in a){delete a[$1]; print $1}' file1 file2
Copy and paste content from one file to another file in vi
Since you already know how to cut/yank text, here are a few ideas for pasting it back into another file:
- Edit the first file, yanking the text you want. Then open your second file from within vi (
:e /path/to/other/file
) and paste it Open both files together in a split window and navigate between them using Ctrl + w, Up/Down either by:
vi -o /path/to/file1 /path/to/file2
- From within the first file, Ctrl + w, s
Related Topics
Read Serial Data Without High CPU Use
How to Add Export Statement in a Bash_Profile File
Ansible: Check If Service Is Listening on a Specific Port
How to Translate X11 Keycode Back to Scancode or Hid Usage Id Reliably
How to Do a While Loop with a String Redirected into It
Limit Top Command to Only Display Top X Processes on Command Line
Top 'Xterm': Unknown Terminal Type
How to Install Devtools Package for R Studio Mounted on Linux Redhat Server
Mongo Daemon Doesn't Run by Service Mongod Start
Loop Through Array of Arrays of String with Spaces
Calculate Total Disk I/O by a Single Process
Linux: Send Mail After a Process Id Finishes or Is Killed