Tag Info

New answers tagged

0

That string is set in /etc/issue. You can (as root) edit that file to change the message. Note that you'll have to have the getty respawn to print the new message; usually failing a few login attempts is enough (but other things will work too, such as killing it, or of course rebooting).


1

Just put the value in a variable compiler_options_for_debug_version="" if something; then compiler_options_for_debug_version="-g -O0" fi Then make sure you quote the variable when you use it: this is just as important. CFLAGS="$compiler_options_for_debug_version" ./configure ...


0

You need to grep the entire line. This can be done as follows - x=1 len=$(wc -l file1.txt | awk '{print $1}') while [ $x -le $len ] do #pat=$(head -$x file1.txt | tail -1) << slow hence changed pat=$(sed "${x}q;d" $1) #cnt=$(grep -c "$pat" file2.txt) < Edited to count all matches cnt=$(grep -o "$pat" ...


0

Probably you could use IFS (Internal Field Separator), and assign the $'\n' to it, meaning that only newlines are the valid separator. Also, to detect multiple occurrences of the same key in the content, we could use grep -o option. Example bash script could be like the following: IFS=$'\n' for string in `cat key.txt` do $string >> out.txt grep ...


1

Try this instead: fgrep -of file1.txt file2.txt | sort | uniq -c Beware that this will only find the exact phrases. If the spacing is different, it won't find them.


0

For the specific example you show, all of these will save cluster1 in the variable $name: sed name=$(sed 's/.*="\(.*\)".*/\1/' <<<$string ) GNU grep (compiled with PCRE support) name=$(grep -oP '[^"]+(?="/>)'<<<$string ) Perl name=$(perl -pe 's/.*="(.*)".*/\1/' <<<$string ) If your shall doesn't support the ...


1

With GNU grep: a="$(grep -oP 'name="\K[^"]*(?="/>)' file)" echo "$a" With GNU sed: a="$(sed -E 's|.*name="([^"]*)"/>.*|\1|' file)" echo "$a" Output: cluster1


2

You said this in a comment: above string is in variable. I need to extract each section(first,second,third) and store it different variables So let's just split it. IFS=\" #set the shell's field separator set -f #don't try to glob set -- $var #split on $IFS var1=$2 var2=$4 var3=$6 #yay unset IFS ...


1

Building on (and somewhat simplifying) ludvik02's sed answer: AA='"abcd efgh" "ijkl mnop" "qrst uvwxyz"' AA1=$(echo "$AA" | sed -r 's/^([^"]*"){1}([^"]*).*/\2/') AA2=$(echo "$AA" | sed -r 's/^([^"]*"){3}([^"]*).*/\2/') AA3=$(echo "$AA" | sed -r 's/^([^"]*"){5}([^"]*).*/\2/') (Note that this ↑ is different on ...


2

I am not sure how you want to input the string. This has the effect you want to achieve, but it might need to be modified according to how the string is entered: aa() { echo $3 ; } ; aa "abcd efgh" "ijkl mnop" "qrst uvwxyz" Edit: So, if it is in variable (it has to be defined with quoted ") : AA="\"abcd efgh\" \"ijkl mnop\" \"qrst uvwxyz\"" echo $AA ...


1

Bash apparently has assosiative array support, but I don't recommend to use it because there's no easy way to pass it to a function as argument. Instead this script defines key/value pairs interleaved in a simple array and pass them to format() as ordinal parameters. #!/bin/bash format() ( T="$1" shift while test $# -ge 2; do ...


4

Because you told Bash to: ~$ echo "/path/to/res/${jsArray[@]}.js" /path/to/res/moment.js datatable.js jquery.js jquery.tmpl.js dt_jq_ui.js report_app.js.js You are just giving one long string. What you want to do is something like ~$ for f in "${jsArray[@]}.js" do echo "/path/to/res/$f" done /path/to/res/moment.js /path/to/res/datatable.js ...


4

Because that's what you're giving your loop: $ jsArray=(moment.js datatable.js jquery.js jquery.tmpl.js dt_jq_ui.js report_app.js) $ echo "/path/to/res/${jsArray[@]}.js" /path/to/res/moment.js datatable.js jquery.js jquery.tmpl.js dt_jq_ui.js report_app.js.js Or, to take a simpler example: $ arr=(a b c ); $ for f in "foo ${arr[@]} bar"; do echo "$f"; ...



Top 50 recent answers are included