grep, vim, fg tricks learnt in Friday meeting
vim search whole world
Yes, when using Vim, you can search for whole words by wrapping them in
\<
and\>
. Here's how to do it:To search for a whole word, use the command
/\<your-word\>
. In your case, if you want to search for the whole word "typeof", you would use:
To search for a whole word, use the command /\<your-word\>
. In your case, if you want to search for the whole word "typeof", you would use:
v/\<typeof\>
Then press Enter. Vim will highlight all instances of the word "typeof" on its own, and not as part of another word.
You can navigate between instances using n
for the next instance and N
for the previous one.
Please note that searching in Vim is case sensitive by default. If you want to do a case-insensitive search, use \c
in your search pattern, like this:
\ctypeof
grep search end of line for a file
└─$ grep "^#" platform.c
#pragma pack(push, 1)
#pragma pack(pop)
#pragma pack(push, 1)
#pragma pack(pop)
└─$ grep "1$" platform.c
true = 1
CTL_BUS_ISA=1
NET_TR_RIF_TIMEOUT=1
Counting Matches: Use
-c
to count the number of lines that match the pattern. For example,grep -c "pattern" file
will return the number of lines in "file" that contain "pattern".Inverting Match: Use
-v
to display the lines that do not match the pattern. For example,grep -v "pattern" file
will return the lines in "file" that do not contain "pattern".
grep c2rust result-31.log| grep -v "generic" | less
👍👍👍 grep -v "^#" file > new-file.c
grep -v "^# " platform.c > new-platform.c
Searching for a Whole Word: Use-w
to search for a whole word. For example,grep -w "pattern" file
will return the lines in "file" that contain "pattern" as a whole word.Searching for a Pattern in Files with Specific Extension: For example,
grep -r --include="*.c" "pattern" directory/
will search for "pattern" in all C files (*.c) in the specified directory and its subdirectories.
fg:bring the job back to the foreground
bg: continue job in background
# Run a command that will take some time to finish, such as 'ping'
ping www.google.com
# Press 'ctrl+z' to pause the job. You will see output like:
# [1]+ Stopped ping www.google.com
# Use 'bg' to continue the job in the background
bg
# Check the current background jobs
jobs
# You will see output like:
# [1]+ Running ping www.google.com &
# Now you can run other commands in the foreground, like:
ls -l
# Use 'fg' to bring the job back to the foreground
fg
# Now that the job is in the foreground again, you can stop it by pressing 'ctrl+c'.