New answers tagged

0

Use grep to find the string at the start of the line and an array to save the results: IFS=$'\n' lines=( $(grep '^string' file.txt) ) grep '^string' file.txt finds the string string at the start of lines of file file.txt The array lines contains the matched lines, the IFS=$'\n' makes each line an array element Now you can iterate over the results using ...


1

One way to do it is to use the end match marker: %s/\n\ze\D/\t/ Another way to do it is to using negative lookahead: %s/\n\d\@!/\t/ They are not exactly equivalent, the second will also replace the last newline in a file.


3

You're almost there, but your regular expression is replacing both the newline and the non-digit with a tab. How about replacing every newline followed by a non-digit with a tab and that same non-digit? %s/\n\(\D\)/\t\1/g The escaping is a bit messy, but basically you have a grouping around the \D that will capture whatever the non-digit is. This is then ...


-2

I hope this will help you :%s#\n.\D#\t#g


2

You can search for a specific integer with a regular expression. Search for the digits preceded by either the beginning of the data or a non-digit character, and likewise after the digits. grep -e '^6$' -e '^6[^0-9]' -e '[^0-9]6$' -e '[^0-9]6[^0-9]' # BRE syntax grep -E '(^|[^0-9])6($|[^0-9])' # ERE syntax An entire-word ...


1

I guess this wasn't such an obscure need. My regular programming editor, pluma supports this via the "find" dialog using the option "Match entire word only". I'm sure many other editors have this as well -- although at the moment, apparently not pluma's ancestor, gedit.


6

grep -E '\b6\b' \b is a "word boundary" Edit: After pointing @nobar in the right direction, he found/pointed_out the shortcut-option -w (word-regexp) in the manpage, which simplifies the above to: grep -w 6 If used a lot, you could use a function similar to wgrp(){ grep -w "$1" "$2"; } Note (to @glenn-jackman): If you don't quote "$2" here, you can ...


3

Since you're not actually changing the "cast" line: sed '/cast \$recv \$UE_CAPABILITY_ENQUIRY/{a\ set trans_id 1 n;d}' file As Kusalananda comments, this command: when one of the wanted "cast" lines is found: append the new line take the next line from the file (the unwanted "set" line) and delete it In hindsight, this does not ...


0

You can try this plugin. https://github.com/tpope/vim-abolish This plugin can help you to match not just the case sensitive text, also its variants too. Like /good{,ies} will match both good as well as goodies. Similarly, it can replace with case sensitive as well as variant included. :%S/long/short/g will replace long with short, Long with Short,...


0

Here is a quick script for search pdf in the current directory : #!/bin/bash if [ $# -ne 1 ]; then echo "usage $0 VALUE" 1>&2 exit 1 fi echo 'SEARCH IS CASE SENSITIVE' 1>&2 find . -name '*.pdf' -exec /bin/bash -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "$0"' $1 \;



Top 50 recent answers are included