sorting - how can i make grep extract string by length in bash? -


i want able extract word thats specific length in wordlist , extract list.

if run:

grep -op '\b(\w{7})\b' infile >> outfile 

eveything run fine , words extracted when run in bash script, nothing gets outputted. if put double quotes causing length number being read, still syntax error.so script looks this:

read -p "what in:" in read -p "what out:" out read -p "what char num:" char  grep -op '\b(\w{$char})\b' $in >> $out 

what missing?

you need have double quotes bash expands variables in strings

try

grep -op "\b(\w{$char})\b"  

seeing in action:

input file

$ cat file1 dockerkill container docker anothercontainer dockerput contain 

script:

$ cat script.sh char="6" grep -op "\b(\w{$char})\b" file1 

output

$ ./script.sh docker 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -