Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (mimi_x3):

anyone know about shell scriping?

OpenStudy (mimi_x3):

Ok, I have a file dictionary, in a text file. so i want to move all the letters that starts with A in a different file. So I grep the words, then I want to redirect the command using shell notation into a different file. How am i able to do that?

OpenStudy (mimi_x3):

Like I want to move all the words that I have grepped into another file.

OpenStudy (mimi_x3):

Using shell.

OpenStudy (mimi_x3):

I'm using the C btw, like the mac terminal

OpenStudy (mimi_x3):

I don't seem to be able to do it, I keep on saving an empty file.

OpenStudy (bibby):

> foo.txt

OpenStudy (mimi_x3):

i keep on saving an empty file

OpenStudy (bibby):

what's the full command you're typing into the terminal? are you sure the grep isn't returning an empty file

OpenStudy (mimi_x3):

grep -i '^[a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z]$' mywords

OpenStudy (mimi_x3):

I get an output of words

OpenStudy (mimi_x3):

but i want to redirect the words into a different file

OpenStudy (bibby):

grep -i '^[a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z]$' mywords >foo.txt

OpenStudy (mimi_x3):

THANKSSSSSS

OpenStudy (bibby):

yay

OpenStudy (mimi_x3):

how to use fgrep

OpenStudy (mimi_x3):

to find a nine letter word

OpenStudy (bibby):

man fgrep because I dunno I'm assuming you can use the same regex of [a-zA-z] 9 times

OpenStudy (mimi_x3):

in this file, and the other dictionary file

OpenStudy (bibby):

this is the grep syntax grep '<pattern>' file1 file2...filenames.... fgrep [a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z] mywords mywords2

OpenStudy (mimi_x3):

how do i search for 9 letters words in my file, from the other dictionary file

OpenStudy (bibby):

would fgrep -i [a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z] mywords mywords2 not work?

OpenStudy (mimi_x3):

nope

OpenStudy (bibby):

I need more than that. errors etc.

OpenStudy (mimi_x3):

nothing happens lol

OpenStudy (bibby):

lol, what are the filenames?

OpenStudy (mimi_x3):

http://gyazo.com/4707247b09ad4b79f14654fb9191acb1

OpenStudy (bibby):

try copying your original regex pattern like so: fgrep -i '^[[a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z]$' 9words mywords things to note: my thing didn't have single quotes or the ^/$

OpenStudy (mimi_x3):

nothing happens aslo

OpenStudy (bibby):

uh try removing the extra bracket? this is a mess :/ fgrep -i '^[a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z]$' 9words mywords

OpenStudy (mimi_x3):

i have already made a file that contains the words

OpenStudy (mimi_x3):

so i need to somehow make a pipeline

OpenStudy (bibby):

use the |

OpenStudy (mimi_x3):

to match the 9 letter words with the dictionary file

OpenStudy (bibby):

so you have a file of 9 letter words and you want to see which ones are in the dictionary?

OpenStudy (mimi_x3):

which one matches

OpenStudy (mimi_x3):

like the 9 letter word luminesce

OpenStudy (mimi_x3):

matching with photoluminescence

OpenStudy (bibby):

that's a bit different, gimme a bit, do you have any idea how you'd start?

OpenStudy (mimi_x3):

apparently fgrep

OpenStudy (rsmith6559):

A couple of things. A single > creates a new file, zeroing the file if it exists. >> appends to the target file, in BASH, but probably not sh, it will create a file if needed. The pipe operator "|" pipes stdout from one command to stdin of another command. FWIW, I only use egrep. IMO, it's too much of a hassle to remember whether something is Basic Regular Expression syntax or Extended Regular Expression syntax. That can make your RE: egrep -i '^[a-z]{9}$' or egrep '^[[:alpha:]]{9}$' using character classes.

OpenStudy (anonymous):

shell scripting is working with commads on unix and linux shells , like using ls -l to list files in linus

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!