Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Shell script with regular expressio
Name: terry Date: December 25, 2002 at 22:46:27 Pacific OS: unix CPU/Ram: -
Comment:
Hi all, I have a problem about developing shell script to extract words with regular expression. For example, I have one text file that contain sth below....
This is a pen.I have a car.My name is John I have no pencil but I can find for you. aaaaaa bbb pkkkkkkkdcils lss
I want my word in this text file that begin with "p" and end with "cil" (p*cil) in this text file you can find pencil in line 2 and pkkkkkkkdcil in line 3
that i can do with grep.... but there is a problem that I want only word i want pencil and pkkkkkkkdcil only.
Name: James Boothe Date: December 26, 2002 at 06:55:06 Pacific
Reply:
Since grep outputs entire lines that contain the target expression, and you want individual words, we can first convert the file to one word per line:
fmt -1 myfile | grep ^p.*encil$
The above will print words that begin with p and end with cil. The last line of your test file contains the word pkkkkkkkdcils which would not qualify since it ends with cils and not cil.
Summary: Hi i've been trying to write shell script with awk that I want to search a substring with variable of shell script In old one ,I wrote awk that find 'xxx' in myfile : #!/bin/ksh awk '/xxx/' myfile...
Summary: thanks man....this help. i'm really new to doin shell script and learning some of the command is so weird, compare to what i'm used to in regular programming language. you help alot already but i'm...
Summary: Can anyone help me with this assignment. Write a shell script file to read 5 student names (First and Last name) and their grades using a while loop. Find the average, maximum and minimum of grades ...