New answers tagged

0

Try this, then: xmlstarlet sel -t -v //Output_Path -nl data.xml


0

Not a direct answer to your question. But grep has an option to ignore all binary files including *.pyc. The option is -I grep -rI hello .


0

Using your question (slightly modified, with a line-break before the but not aaeiou because of the 'aa') as input: $ cat hehe.txt The problem is to write a script that takes a file as argument and prints all the lines that contain -at least- all the vowels , -regardless of ordering-, but with [no two same consecutive vowels]. e.g aeaiou is allowed, but ...


0

Instead of invoking grep several times, you could also use a single invocation of sed, either sed -rn '/(aa|ee|ii|oo|uu)/d; /a/{/e/{/i/{/o/{/u/p}}}}' or sed -rn '/([aeiou])\1/d; /a/{/e/{/i/{/o/{/u/p}}}}' if you prefer to use back-references.


1

As long as you want to exclude the entire line if there are double vowels, this should work: grep -i a file | \ grep -i e | \ grep -i i | \ grep -i o | \ grep -i u | \ grep -v -i '\([aeiou]\)\1'


0

I believe that you can do this with "cut", using just one binary, avoiding pipes, reaching the same results as the other answers, but in a more elegant way :), like this: $ cut -d : -f 1,6 /etc/passwd root:/root daemon:/usr/sbin bin:/bin sys:/dev sync:/bin games:/usr/games man:/var/cache/man lp:/var/spool/lpd mail:/var/mail news:/var/spool/news .... If ...


0

This solution user "123" created for me on another question was able to strip suffixes reliably without mangling words. I wanted to come back and answer this question so that anyone seeking a similar solution could get a good answer. awk 'FNR==NR{a[$0 "s"]++;next}!($0 in a)' file.txt file.txt awk 'FNR==NR{a[$0 "ed"]++;next}!($0 in a)' file.txt file.txt awk '...


2

You could process the list of all layouts and for each item in the list check every corresponding variant for level3 symbols: list=($(sed '/! layout/,/^$/!d;//d s/[[:blank:]]*\([^[:blank:]]*\)[[:blank:]].*/\1/' \ < /usr/share/X11/xkb/rules/evdev.lst)) layouts=("${list[@]##*/}") for i in "${layouts[@]}"; do sed -n '\|//.*level3|d;H;/xkb_symbols/{s/.*"\(....


1

There is also the findmnt command, which can print the number of bytes or a "human" number (powers of 1024 with non-iso abbreviations, sadly): $ findmnt -no size /mnt/xyz 9.7G $ findmnt -bno size /mnt/xyz 10434699264


4

You can do it without the grep: df --output=target,size /mnt/xyz | awk ' NR==2 { print $2 } ' df accepts as argument the mount point; you can tell to awk too to print both the second line only (NR==2) , and the 2nd argument, $2. Or better yet, cut the target as you are not outputting it, and it becomes: df --output=size /mnt/xyz | awk ' NR==2 ' When I ...


2

You can do that with bash itself, using command substitution and then parameter expansion. First take the output of the command in a variable by using command substitution $(), and then use parameter expansion to replace all newlines with spaces ${variable//$'\n'/ }: $ myVariable=$(grep "type" /root/myFile | cut-d'=' -f2) $ myVariable=${myVariable//$'\n'/ ...


1

myVariable=`grep "type" /root/myFile | cut-d'=' -f2` What is between back-ticks (`) is run and the output is assigned to myVariable. If your current output is separated by line feeds (\n), then you may want to replace them with spaces with tr such as: myVariable=`grep "type" /root/myFile | cut-d'=' -f2`|tr '\n' ' '` Note: Some people prefer using the $...


-1

Using only sed (with -r flag for extended regex) echo "aaa string1 bbb aaa string2 bbb aaa string3 bbb" | sed -r 's/(aaa|bbb) ?//g' Returns string1 string2 string3 You also have this version using tr and grep (with -vE): echo "aaa string1 bbb aaa string2 bbb aaa string3 bbb" | tr ' ' '\n'| grep -vE '(aaa|bbb|^$)' Returns string1 string2 string3 ...


1

If your system's grep supports PCRE, you could maybe do $ echo 'aaa string1 bbb aaa string2 bbb aaa string3 bbb' | grep -oP '(?<=(aaa|bbb) )\w*?(?= (aaa|bbb))' string1 string2 string3 or if you need to handle more general amounts of surrounding whitespace $ echo 'aaa string1 bbb aaa string2 bbb aaa string3 bbb' | grep -oP '(aaa|bbb)\s+\K\w*?(?=\s+...


0

If you are fine with something structured like: string1 string2 string3 I would just simply replace you delimiters with a newline. Something such as this should get you close: sed "s/\(aaa\)\|\(bbb\)/\n/g" test.txt Edit As pointed out by @clk below, my first answer may give double newlines. Changing to something such as: sed "s/\(\s\)\?aaa\(\s\)\?/...


0

This is the completely unquoted version: grep ^\\*\\* test.out. To pass a literal backslash from the shell to grep, it needs to be escaped. This works as long as you have no files in the directory starting with ^\ and containing another backslash.


3

It's not the shell None of the answers so far has touched on the real problem. It would be helpful to explain why it does not work as you expect. grep -i "^**" test.out Because you have quoted the pattern to grep, * is not expanded by the shell. It is passed to grep as-is. This is explained in the manual page[1] for bash[2]: Enclosing characters in ...


7

As you wanted to check the line which starts with ** and ends with ), you can combine two grep operation like this, grep '^*\*' test.out | grep ')$' Or with single grep command like this, grep -E '^\*\*.*\)$' test.out Explanation ^\*\* : match line which starts with ** .* : match everything after ** \)$ : match line which also has ) at the end of ...


2

Other options. You can use sed or awk also $ sed -n '/^*\*/p' test.out $ awk '/^*\*/' test.out To know lines that end with ) use also grep or sed or awk $ grep ')$' test.out $ sed -n '/)$/p' test.out $ awk '/)$/' test.out


13

Use the \ character to escape the * to make it a normal character. grep '^\*\*' test.out Also note the single quote ' and not double quote " to prevent the shell expanding things


0

List File Names ending with the given pattern ls -1 | grep -isE "*.%ox9" grep for the lines containing the pattern grep -isE "*.%ox9" *


0

Is this the character you are looking for? printf "\x9" I dont if is the best but works: tail -n1 fileendingwithx9 | grep "$(printf "\x9")"


1

As others have pointed out, grep isn't the best tool for this. If you insist on using it, and if your grep supports the -o (only print the matched portion of the line) and -P (use Perl Compatible Regular Expressions), you can do this: $ grep -oP '^[^:]+|.*:\K[^:]+(?=:[^:]+)' /etc/password terdon /home/terdon bob /home/bob Note that this will print all ...


17

You can use cut to split files with columns on a specific delimiter: cut -d: -f6 /etc/passwd Or -f1,6 for columns (fields) 1 and 6.


9

Grep is really not the tool for parsing out data this way, grep is more for pattern matching and you're trying to do text-processing. You would want to use awk. awk -F":" '$7 == "/bin/false" {print "User: "$1 "Home Dir: "$6}' /etc/passwd awk The command -F":" Sets the data delimiter to : $7 == "/bin/false" Checks if the 7th data column is /bin/false {...


0

At least with GNU tools: grep -rcZ "some_pattern" | awk -F'\0' '{s+=$NF}END{print s}' This is likely superior in speed compared to wc -l. It also works for files with newline in name.


4

I was able to put the answer together with help from this question. The program "wc" program counts newlines, words and byte counts. The "-l" option specifies that the number of lines is desired. For my application, the following worked nicely to count the number of instances of "somePattern": $grep -r "somePattern" | wc -l


1

perl -l0 -ne 'print for /\\subimport\{\}\{(.*?)\}/g' file.tex Would print the filenames inside those \subimport{}{...} functions NUL-delimited. You can pipe that to xargs -0 grep -l gastric -- to find which of those files contain gastric.


0

In the end, I use the search in directory by the script here with a redirection to Vim. It would be great to get something like that work in Geany IDE directly.


0

I tend to use Perl. sed or awk is fine in this case, but sometimes the flexibility is Perl is useful. perl -pi -e 's/^(mynetworks.*)/$1 0.0.0.0\/0/' /path/to/file or if this is in a pipe chain cat file | perl -pe 's/^(mynetworks.*)/$1 0.0.0.0\/0/'


0

Typical sed one-liner problem. The pattern is: /^"/ {s/[^a-zA-Z0-9]//g; h;}; /^ *dollar\-balance/ {s/^[^=]*=//; H; x; s/\n/\t/; p;} Usage & output: $ cat /tmp/file | sed -ne '/^"/ {s/[^a-zA-Z0-9]//g; h;}; /^ *dollar\-balance/ {s/^[^=]*=//; H; x; s/\n/\t/; p;} ' | sort -k2 -n -r 01d6e2509e4f495b92c2a8fac850f4d6 877164.34 ...


1

To add the specified text to a line in the file - if that line is the only one that starts with mynetworks, you can do this: sed --in-place '/^mynetworks/s_.*_& 0.0.0.0/0_' /path/to/file


3

Using sed sed -i 's+^mynetworks.*+& 0.0.0.0/0+' log.txt Using awk awk '/^mynetworks/ {$0=$0" 0.0.0.0/0"} 1' log.txt or awk '{if ($1 ~ /^mynetworks/) print $0, "0.0.0.0/0"; else print $0}' log.txt Using bash while read -r line ; do [[ $line == mynetworks* ]] && line+=" 0.0.0.0/0" echo "$line" done < log.txt


2

If you do not quote the parameter, the "&" in the parameter will put part of this into the background, and run an incomplete command. Something like this: > elinks -dump 'https://www.amazon.com/s/ref=sr_nr_p_lbr_music_artists__0?fst=as%3Aoff&rh=i%3Aaps%2Ck%3Athe+prodigy%2Cp_lbr_music_artists_browse-bin%3AThe+Prodigy&keywords=the+prodigy\&...


1

With GNU grep, GNU sed, GNU sort and awk: grep -e '{' -e 'dollar' file | sed '/{/{N;s/\n//}' | sort -t = -k2nr | awk -F'[="]' '{print $2,$4}' Output: 01d6e250-9e4f-495b-92c2-a8fac850f4d6 877164.34 01eea52c-0419-40b3-838f-6cd5300d4393 101149 00315457-ca9e-4c45-87e6-eef632acffce 25004 00b5c95a-8a78-4faa-9d13-a83aa20d4702 25000 00e9b66b-3afa-4182-b024-...


0

try sed -e 's/^.*"\([^" ]*\)"".*/\1/' log | sort | uniq egrep -o '[^"]+@[^"]+' log | sort | uniq where -o print only matched pattern [^X]+ any number (> 0) of char different from X please note sed solution relays on a typo/feature in your file (double double quote) grep solution relays on foo@some.where pattern awk (or perl for that matter) is ...


0

I would try something like: awk -v pattern="Testing:" '$0 ~ pattern { sub(pattern, " *"); print }' This should work with any version of sed, since it contains no obvious extensions. It is not necessary to handle the newlines explicitly as long as you take care to quote your variables properly, in order to prevent word splitting.


1

Those files and directories do not belong to you, they belong to the root user, and have too restrictive access permissions for find and grep to work. Therefore, find complains about not being able to enter the directory /home/masi/.dbus (to do its job), and grep complains about not being able to read the files (to do its job). The files and directories do ...


0

I'd use perl here: perl -lne ' for (/\w+/g) {$count{lc $_}->{$ARGV}=undef} END {print "$_: " . keys %{$count{$_}} for keys %count}' ./*


0

for file in Employee Salary Dependents; do prefix="${file:0:1}" # First character of the filename sed "1,2d;s/ //;s/^/$prefix/" "$file" done


0

FreeBSD's pgrep excludes ancestors of the pgrep process, including the script instance that ran it. Linux's pgrep doesn't have a corresponding feature. You can exclude the script instance manually. The process id to exclude is in $$. You do need to be a bit careful to also avoid any subshell: the most straightforward method pgrep … | grep -v "^$$ " might ...


0

Just add x to the flags: #!/usr/bin/env bash pgrep -flx "pgrep.sh" Tested in Ubuntu and it doesn't print anything to the output (if this ...


3

#! /usr/bin/awk -f /"dvorak"/ {dvorak++}; /{/ && dvorak {b++} ; /}/ && dvorak {b--} ; dvorak && b == 0 && NR > 1 { print NR; exit } $ ./find-dvorak.awk /usr/share/X11/xkb/symbols/us 248 This uses a counter (b) which gets incremented every time it sees an open-curly-bracket { and decremented whenever it sees a ...


4

This sed script prints the line number of the line matching /^};/ in the range of lines from /xkb_symbols "dvorak" {/ to the next /^};/ (which will be the same }; as the one we get the line number for): /xkb_symbols "dvorak" {/,/^};/{ /^};/= } If you need both start and end line numbers: /xkb_symbols "dvorak" {/,/^};/{ /xkb_symbols "...


1

A somewhat different solution: Scramble the lines in your text files with a cron job every day. Your script then picks the first line. Cron job (requires a sort that can "sort" data randomly with -R): 0 0 * * * sort -R -o wotd_data.txt wotd_data.txt Or, if your cron understands @daily (see man 5 crontab): @daily sort -R -o wotd_data.txt wotd_data.txt ...


1

If a sequential walk through the file is not acceptable, then here's my suggestion; it will take more than 230 years to cover every line in the file, and will repeat words back-to-back at some yet-undetermined point in the future. I made it a bit more flexible by computing the number of lines (word definitions) in the 'words' file at run-time, so if you ever ...


2

Use the RANDOM variable of your shell to get a random number, but seed the random number generator with today's date first (if the script hasn't been used since midnight). Then pick that line out of the file. In other words (Bash below)... wotd_data="wotd_data.txt" stamp="$HOME/.wotd-stamp" stamp_random="$HOME/.wotd-random" date_now=$( date +"%Y%m%d" ) ...


2

Modulus math! $ today=`date +%Y%m%d` $ echo $(( today % 86036 + 1 )) 28193 ... with possibly the 86036 instead being wc -l that file in the event the length of that file changes ...


10

From the character of the wine's output I conclude that it is some kind of error message, therefore probably is redirected to stderr, not stdout. In that case pipe doesn't transmit the message and next command (while) has nothing on its input. To overcome the problem you need to e.g. redirect wine's stderr to stdout by adding 2>&1 in front of the pipe ...



Top 50 recent answers are included