Re: extract string from filename

2006-01-13 Thread Paul Lussier
Tom Buskey <[EMAIL PROTECTED]> writes: > Unix Shell Programming by Kochan and Wood is a classic on shell programming > > > Portable Shell Programming by Blinn > The Awk Programming Language by Aho, Weinberger and Kernighan I'm also a big fan of Kernighan and Pikes, "The UNIX Programming Environme

Re: extract string from filename

2006-01-13 Thread Paul Lussier
[EMAIL PROTECTED] (Kevin D. Clark) writes: > Zhao Peng writes: > >> I'm back, with another "extract string" question. //grin > > > find FOLDERNAME -name \*sas7bdat -print | sed 's/.*\///' | cut -d _ -f 2 | > sort -u > somefile.txt Or, to

Re: extract string from filename

2006-01-13 Thread Dan Jenkins
Zhao Peng wrote: string1_string2_string3_string4.sas7bdat abc_st_nh_num.sas7bdat abc_st_vt_num.sas7bdat abc_st_ma_num.sas7bdat abcd_region_NewEngland_num.sas7bdat abcd_region_South_num.sas7bdat My goal is to : 1, extract string2 from each file name 2, then sort them and keep only unique ones 3

Re: extract string from filename

2006-01-13 Thread Michael ODonnell
"cat -n" will number output lines ___ gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss

Re: extract string from filename

2006-01-13 Thread Ben Scott
On 1/13/06, Ben Scott <[EMAIL PROTECTED]> wrote: > On 1/13/06, Zhao Peng <[EMAIL PROTECTED]> wrote: > > Is it possible to number the extracted string2? > > find -name \*sas7bdat -printf '%f\n' | cut -d _ -f 2 | sort | uniq | cat -n I forgot to mention: If the *only* files in that directory are t

Re: extract string from filename

2006-01-13 Thread Ben Scott
On 1/13/06, Zhao Peng <[EMAIL PROTECTED]> wrote: > Is it possible to number the extracted string2? find -name \*sas7bdat -printf '%f\n' | cut -d _ -f 2 | sort | uniq | cat -n Run that pipeline in the directory you are interested in. The find(1) command finds files, based on their name or oth

Re: extract string from filename

2006-01-13 Thread Jeff Kinz
On Fri, Jan 13, 2006 at 11:40:26AM -0500, Zhao Peng wrote: > Kevin, > > Thank you very much! I really appreciate it. > > I like your "find" approach, it's simple and easy to understand. > > I'll also try to understand your perl approach, when I got time to start > learning it. (Hopefully it won

Re: extract string from filename

2006-01-13 Thread Zhao Peng
hao Kevin D. Clark wrote: Zhao Peng writes: I'm back, with another "extract string" question. //grin find FOLDERNAME -name \*sas7bdat -print | sed 's/.*\///' | cut -d _ -f 2 | sort -u > somefile.txt or perl -MFile::Find -e 'find(sub{$string2 = (split

Re: extract string from filename

2006-01-13 Thread Larry Cook
Zhao Peng wrote: My goal is to : 1, extract string2 from each file name 2, then sort them and keep only unique ones 3, then output them to a .txt file. (one unique string2 per line) It is really interesting how many ways there are to do things in *nix. My first reaction, if this is a one time

Re: extract string from filename

2006-01-13 Thread Bill McGonigle
On Jan 12, 2006, at 19:40, Zhao Peng wrote: I also downloaded an e-book called "Learning Perl" (OReilly, 4th.Edition), and had a quick look thru its Contents of Table, but did not find any chapter which looks likely addressing any issue related to my question. Good start. Read these section

Re: extract string from filename

2006-01-13 Thread Tom Buskey
On 1/12/06, Ben Scott <[EMAIL PROTECTED]> wrote: On 1/12/06, Zhao Peng <[EMAIL PROTECTED]> wrote:> I'm back, with another "extract string" question. //grin  It sounds like you could use a tutorial on Unix text processing and command line tools, specifica

Re: extract string from filename

2006-01-13 Thread Ted Roche
On Jan 12, 2006, at 8:25 PM, Ben Scott wrote: It sounds like you could use a tutorial on Unix text processing and command line tools, specifically, one which addresses pipes and redirection, as well as the standard text tools (grep, cut, sed, awk, etc.). While Paul's recommendation about the

Re: extract string from filename

2006-01-12 Thread Kevin D. Clark
Zhao Peng writes: > I'm back, with another "extract string" question. //grin find FOLDERNAME -name \*sas7bdat -print | sed 's/.*\///' | cut -d _ -f 2 | sort -u > somefile.txt or perl -MFile::Find -e 'find(sub{$string2 = (split /_/)[2]; $seen{$strin

Re: extract string from filename

2006-01-12 Thread Python
On Thu, 2006-01-12 at 19:40 -0500, Zhao Peng wrote: > For example: > abc_st_nh_num.sas7bdat > abc_st_vt_num.sas7bdat > abc_st_ma_num.sas7bdat > abcd_region_NewEngland_num.sas7bdat > abcd_region_South_num.sas7bdat You're not the only one learning here. I put these names into a file called str2-t

Re: extract string from filename

2006-01-12 Thread Ben Scott
On 1/12/06, Zhao Peng <[EMAIL PROTECTED]> wrote: > I'm back, with another "extract string" question. //grin It sounds like you could use a tutorial on Unix text processing and command line tools, specifically, one which addresses pipes and redirection, as well as the s

extract string from filename

2006-01-12 Thread Zhao Peng
Hi all, I'm back, with another "extract string" question. //grin I have almost 1k small files within one folder. The only pattern of the file names is: string1_string2_string3_string4.sas7bdat Note: 1, string2 often repeat itself across each file name For example: abc_st_

Re: extract string

2006-01-12 Thread Thomas Charron
On 1/11/06, Ben Scott <[EMAIL PROTECTED]> wrote: > I felt really embarrassed with my stupid mistake. //blushYou think you were embarrassed?  There was a certain instance of someone accidentally hitting "Reply to All" to a list message which isstill remembered to this day.  I won't mention any names

Re: extract string

2006-01-11 Thread Kevin D. Clark
Zhao Peng <[EMAIL PROTECTED]> writes: > You said that "there is an extra column in the 3rd line". I disagree > with you from my perspective. As you can see, there are 3 commas in > between "jesse" and "Dartmouth college". For these 3 commas, again, if > we think the 2nd one as an merely indicatio

Re: extract string

2006-01-11 Thread Drew Van Zandt
perl split on the char pair ," Take last element of returned array, either remove the " at the end or replace the one you ate with the split. Keep a running variable containing largest length encountered so far. Add 10 to be safe.  ;-) Any regexp I have to think about for more than 30 seconds is

Re: extract string

2006-01-11 Thread Thomas Charron
On 1/11/06, Bill McGonigle <[EMAIL PROTECTED]> wrote: On Jan 11, 2006, at 08:42, [EMAIL PROTECTED] wrote:> This poses an interesting problem. The "," is being used for two > purposes: a delimiter *AND* as a place holder.Now, for the Lazy, Perl regular expressions are a state machine ofsorts.  I sus

Re: extract string

2006-01-11 Thread Ben Scott
On 1/11/06, Zhao Peng <[EMAIL PROTECTED]> wrote: > Secondly I'm sorry for the big stir-up as to "homework problems" which > flooded the list, since I'm origin of it. *Trust me*, that wasn't a "big" stir-up. Search the list archives for "taxes" if you want to see big ones. The homework thread w

Re: extract string

2006-01-11 Thread Bill McGonigle
On Jan 11, 2006, at 08:42, [EMAIL PROTECTED] wrote: This poses an interesting problem. The "," is being used for two purposes: a delimiter *AND* as a place holder. I tried to prove to myself last night that this method would produce unresolvable ambiguities, but if you think like a state mach

Re: extract string

2006-01-11 Thread Thomas Charron
iar with regular expressions.  You've seen a small snippet in Kenny's example 'sed s/\"//g'.  The 's/\"//g' says to globally replace all quotes with nothing (s = substitute, /1/2/ says 'replace everything matching 1 with 2', in this case, a quote, with

Re: extract string -- TIMTOWTDI

2006-01-11 Thread Paul Lussier
William D Ricker <[EMAIL PROTECTED]> writes: >> On 1/10/06, Paul Lussier <[EMAIL PROTECTED]> wrote: >> > > perl -ne 'split ","; $_ = $_[2]; s/(^")|("$)//g; print if m/univ/;' < >> > > abc.txt > def.txt >> > Egads! [outstanding explanation I didn't have time to write myself removed ] > None of th

Re: extract string

2006-01-11 Thread Kevin D. Clark
Zhao Peng writes: > ... your "grep univ abc.txt | cut -f3 -d, | sed s/\"//g >> dev.txt" > works. It "works" but is it correct? What happens if you pass it the following line of input?: "Aunivz","28","Cambridge Community College" By your original problem description, you don't want to see "C

Re: extract string

2006-01-11 Thread Paul Lussier
Zhao Peng <[EMAIL PROTECTED]> writes: > First I really cannot be more grateful for the answers to my question > from all of you, I appreciate your help and time. I'm especially > touched by the outpouring of response on this list., which I have > never experienced before anywhere else. Zhao, thi

Re: extract string

2006-01-11 Thread klussier
-- Original message -- From: Zhao Peng <[EMAIL PROTECTED]> > Hi All, > > Kenny, your "grep univ abc.txt | cut -f3 -d, | sed s/\"//g >> dev.txt" > works. I mis-read /\ as a simliar sign on the top of "6" key on the > keyboard(so when I typed that sign, I felt st

Re: extract string

2006-01-11 Thread Jon maddog Hall
Zhao, I am really busy right now, so I have not read all of the responses to your problem completely, but I did notice this: [EMAIL PROTECTED] said: > You said that "there is an extra column in the 3rd line". I disagree with > you from my perspective. As you can see, there are 3 commas in betw

Re: extract string

2006-01-10 Thread Zhao Peng
sis, I think, so you could say it's a statistical software, check www.sas.com). We run SAS on a RedHat server, but I basically know nothing about linux before I started working on this position(July, 2005). Fortunately, SAS programming doesn't require much linux knowledge. However, a

Re: extract string -- TIMTOWTDI

2006-01-10 Thread William D Ricker
> On 1/10/06, Paul Lussier <[EMAIL PROTECTED]> wrote: > > > perl -ne 'split ","; $_ = $_[2]; s/(^")|("$)//g; print if m/univ/;' < > > > abc.txt > def.txt > > Egads! That's a literal start at a Perl "bring the grep sed and cut-or-awk into one process", but it's not maximally Perl-ish. It is also i

Re: Homework problems (was: extract string)

2006-01-10 Thread Jim Kuzdrall
On Tuesday 10 January 2006 06:05 pm, Travis Roy wrote: > Just let it go, if you think it's somebody "cheating" then don't > answer, or give them a vague answer or point them to places where > they can learn about it rather then copy it off of. That is my technique too. I get to answer a lot

Re: Homework problems (was: extract string)

2006-01-10 Thread Jeff Kinz
On Tue, Jan 10, 2006 at 08:16:47PM -0500, Christopher Schmidt wrote: > On Tue, Jan 10, 2006 at 07:56:46PM -0500, Thomas Charron wrote: > > A programmer that doesn't know how to grep and split text strings.. > > > > Well.. Isn't.. > > I know of several ways to do it, but none of them would ha

Re: Homework problems (was: extract string)

2006-01-10 Thread Bill McGonigle
On Jan 10, 2006, at 20:16, Christopher Schmidt wrote: The lack of knowledge of a simple command line tool to do what you want it to does not indicate whether someone is a programmer or not. It simply indicates one thing -- their level of experience with core *nix tools. Lack of that is not an i

Re: Homework problems (was: extract string)

2006-01-10 Thread Christopher Schmidt
On Tue, Jan 10, 2006 at 07:56:46PM -0500, Thomas Charron wrote: > A programmer that doesn't know how to grep and split text strings.. > > Well.. Isn't.. I know of several ways to do it, but none of them would have worked as well as the cut solution presented here. I've been working on Linux

Re: Homework problems (was: extract string)

2006-01-10 Thread Jeff Kinz
On Tue, Jan 10, 2006 at 07:56:46PM -0500, Thomas Charron wrote: > On 1/10/06, Bill McGonigle <[EMAIL PROTECTED]> wrote: > > > > On Jan 10, 2006, at 18:05, Travis Roy wrote: > > > How do we, as a list, tell what's a homework problem and what's a > > > legit question. > > I think there's little subst

Re: Homework problems (was: extract string)

2006-01-10 Thread Ben Scott
On 1/10/06, Thomas Charron <[EMAIL PROTECTED]> wrote: >A programmer that doesn't know how to grep and split text strings.. Believe it or not, there are environments *other* then nix, and a great many well-qualified professionals have never touched nix. I don't just mean doze, either. Class

Re: Homework problems (was: extract string)

2006-01-10 Thread Thomas Charron
On 1/10/06, Bill McGonigle <[EMAIL PROTECTED]> wrote: On Jan 10, 2006, at 18:05, Travis Roy wrote:> How do we, as a list, tell what's a homework problem and what's a> legit question.I think there's little substitute for knowing the membership.  Zhao isa programmer for Dartmouth Medical School.   F

Re: extract string

2006-01-10 Thread Paul Lussier
Ben Scott <[EMAIL PROTECTED]> writes: > On 1/10/06, Jon maddog Hall <[EMAIL PROTECTED]> wrote: >> I was the senior systems administrator for Bell Labs in North Andover, MA. I >> got the job without ever having seen a UNIX system. > > Well, really. How many people *had* seen a UNIX system, back

Re: Homework problems (was: extract string)

2006-01-10 Thread Jeff Kinz
On Tue, Jan 10, 2006 at 04:01:05PM -0500, Ben Scott wrote: > On 1/10/06, Jeff Kinz <[EMAIL PROTECTED]> wrote: > > Now your Lug can achieve its financial funding goals simply by charging > > 25 cents for each shell scripting homework problem answered and 50 cents > > for extended explanations such a

RE: Homework problems (was: extract string)

2006-01-10 Thread Brian
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Jim Kuzdrall > Sent: Tuesday, January 10, 2006 5:45 PM > To: gnhlug-discuss@mail.gnhlug.org > Subject: Re: Homework problems (was: extract string) > > > All of

Re: Homework problems (was: extract string)

2006-01-10 Thread Bill McGonigle
On Jan 10, 2006, at 18:05, Travis Roy wrote: How do we, as a list, tell what's a homework problem and what's a legit question. I think there's little substitute for knowing the membership. Zhao is a programmer for Dartmouth Medical School. -Bill - Bill McGonigle, Owner Work:

Re: Homework problems (was: extract string)

2006-01-10 Thread klussier
-- Original message -- From: Jim Kuzdrall <[EMAIL PROTECTED]> > On Tuesday 10 January 2006 04:13 pm, Brian wrote: > > Answer C: Who cares? > > All of us will care when the country has to depend on the products > of today's education system. Get ready for it.

Re: Homework problems (was: extract string)

2006-01-10 Thread Travis Roy
Jim Kuzdrall wrote: On Tuesday 10 January 2006 04:13 pm, Brian wrote: Answer C: Who cares? All of us will care when the country has to depend on the products of today's education system. Get ready for it. The standards are so incredibly low that these graduates will not even know the

Re: Homework problems (was: extract string)

2006-01-10 Thread Jim Kuzdrall
On Tuesday 10 January 2006 04:13 pm, Brian wrote: > Answer C: Who cares? All of us will care when the country has to depend on the products of today's education system. Get ready for it. The standards are so incredibly low that these graduates will not even know the buzz words of technolo

Re: extract string

2006-01-10 Thread Kevin D. Clark
Ben Scott writes: > Is there a tool that quickly and easily extracts one or more columns > of text (separated by whitespace) from an output stream? I'm familiar > with the > > awk '{ print $3 }' > > mechanism, but I've always felt that was clumsy. I've tried to get > cut(1) to do it

Re: Homework problems (was: extract string)

2006-01-10 Thread Travis Roy
t: Homework problems (was: extract string) Assume it is a homework problem. Does it make a real difference whether the student learns the material from the text book, this list, or some random web page found via Google? ___ gnhlug-discuss mailing

Re: extract string

2006-01-10 Thread klussier
-- Original message -- From: Zhao Peng <[EMAIL PROTECTED]> > Kenny, > > Thank you for your suggestion. > > The following line works: > grep univ abc.txt | cut -f3 -d, >> dev.txt. > > > While the following line intended to remove quotes does NOT work: > grep uni

Re: extract string

2006-01-10 Thread Ben Scott
On 1/10/06, Jon maddog Hall <[EMAIL PROTECTED]> wrote: > I was the senior systems administrator for Bell Labs in North Andover, MA. I > got the job without ever having seen a UNIX system. Well, really. How many people *had* seen a UNIX system, back then? ;-) (Sorry, couldn't resist.) > It

Re: extract string

2006-01-10 Thread Jon maddog Hall
[EMAIL PROTECTED] said: >> While the following line intended to remove quotes does NOT work: >> grep univ abc.txt | cut -f3 -d, | sed s/\"//g >> dev.txt >> It resulted in a line starts with ">" prompt, and not output dev.txt > I can't see any reason why what state should be happening. As a matte

RE: Homework problems (was: extract string)

2006-01-10 Thread Brian
Answer C: Who cares? > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Ben Scott > Sent: Tuesday, January 10, 2006 4:01 PM > To: gnhlug-discuss@mail.gnhlug.org > Subject: Homework problems (was: extract string) > > Assume

Re: extract string

2006-01-10 Thread Ben Scott
On 1/10/06, Drew Van Zandt <[EMAIL PROTECTED]> wrote: > While it does seem like a few man page pointers would be better (more > instructive in the long run), I have to admit I wasn't familiar with cut, so > I've learned something from this one. Since we're on the subject... Is there a tool th

Re: extract string

2006-01-10 Thread klussier
-- Original message -- From: Paul Lussier <[EMAIL PROTECTED]> > [EMAIL PROTECTED] writes: > > > Actually, if you are looking for only lines that contain the string "univ", > then you would want to grep for it: > > > > grep univ abc.txt | cut -f3 -d, >> dev.txt. >

Re: extract string

2006-01-10 Thread Ben Scott
On 1/10/06, Paul Lussier <[EMAIL PROTECTED]> wrote: > > perl -ne 'split ","; $_ = $_[2]; s/(^")|("$)//g; print if m/univ/;' < > > abc.txt > def.txt > > Egads! Egads? -- Ben "As I was saying about explanation..." Scott ___ gnhlug-discuss mailing list g

Homework problems (was: extract string)

2006-01-10 Thread Ben Scott
On 1/10/06, Jeff Kinz <[EMAIL PROTECTED]> wrote: > Now your Lug can achieve its financial funding goals simply by charging > 25 cents for each shell scripting homework problem answered and 50 cents > for extended explanations such as rendered below. :-) I was wondering if I should raise the "Ya

Re: extract string

2006-01-10 Thread Drew Van Zandt
While it does seem like a few man page pointers would be better (more instructive in the long run), I have to admit I wasn't familiar with cut, so I've learned something from this one. --Drew

Re: extract string

2006-01-10 Thread Paul Lussier
Zhao Peng <[EMAIL PROTECTED]> writes: > While the following line intended to remove quotes does NOT work: > grep univ abc.txt | cut -f3 -d, | sed s/\"//g >> dev.txt > It resulted in a line starts with ">" prompt, and not output dev.txt I can't see any reason why what state should be happening. A

Re: extract string

2006-01-10 Thread Michael ODonnell
> Ooo, look! - a new business model for Lugs! I happen to like these threads and far from regarding them as a burden I think they're a pleasant diversion and extremely useful as learning opportunities. But I've been asking for a long time when our IPO will be happening; we've got more talent an

Re: extract string

2006-01-10 Thread Paul Lussier
[EMAIL PROTECTED] writes: > Actually, if you are looking for only lines that contain the string "univ", > then you would want to grep for it: > > grep univ abc.txt | cut -f3 -d, >> dev.txt. Why are you appending to dev.txt? (or def.txt even). Are you assuming the file already exists and don't w

Re: extract string

2006-01-10 Thread Paul Lussier
Ben Scott <[EMAIL PROTECTED]> writes: > Here's one way, as a Perl one-liner: > > perl -ne 'split ","; $_ = $_[2]; s/(^")|("$)//g; print if m/univ/;' < > abc.txt > def.txt Egads! -- Seeya, Paul ___ gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug

Re: extract string

2006-01-10 Thread Paul Lussier
Zhao Peng <[EMAIL PROTECTED]> writes: > Hi > > Suppose that I have a file called abc.txt, which contains the > following 5 lines (columns are delimited by ",") > > "name","age","school" > "jerry" ,"21","univ of Vermont" > "jesse","28","Dartmouth college" > "jack","18","univ of Penn" > "john","20",

Re: extract string

2006-01-10 Thread Jeff Kinz
Ooo, look! - a new business model for Lugs! Achieve Lug financial independence today! Now your Lug can achieve its financial funding goals simply by charging 25 cents for each shell scripting homework problem answered and 50 cents for extended explanations such as rendered below. :-) All we need

Re: extract string

2006-01-10 Thread Ben Scott
On 1/10/06, Zhao Peng <[EMAIL PROTECTED]> wrote: > While the following line intended to remove quotes does NOT work: > grep univ abc.txt | cut -f3 -d, | sed s/\"//g >> dev.txt > It resulted in a line starts with ">" prompt, and not output dev.txt The ">" prompt indicates the shell thinks you are

Re: extract string

2006-01-10 Thread Ben Scott
On 1/10/06, Whelan, Paul <[EMAIL PROTECTED]> wrote: > Like so: cat abc.txt | cut -d, -f3 1. Randal Schwartz likes to call that UUOC (Useless Use Of cat). :-) You can just do this instead: cut -d, -f3 < abc.txt If you like the input file at the start of the command line, that's legal, to

Re: extract string

2006-01-10 Thread Ben Scott
On 1/10/06, Zhao Peng <[EMAIL PROTECTED]> wrote: > how could I extract the string which > contains "univ" and create an output file called def.txt, which only has > 3 following lines: Here's one way, as a Perl one-liner: perl -ne 'split ","; $_ = $_[2]; s/(^")|("$)//g; print if m/univ/;' < abc.tx

Re: extract string

2006-01-10 Thread Zhao Peng
From: "Whelan, Paul" <[EMAIL PROTECTED]> Like so: cat abc.txt | cut -d, -f3 Thanks. -Original Message- From: Zhao Peng [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 10, 2006 11:51 AM To: gnhlug-discuss@mail.gnhlug.org Subject: extract string Hi Suppose t

RE: extract string

2006-01-10 Thread klussier
| cut -d, -f3 > > Thanks. > > -Original Message- > From: Zhao Peng [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 10, 2006 11:51 AM > To: gnhlug-discuss@mail.gnhlug.org > Subject: extract string > > Hi > > Suppose that I have a file called abc

RE: extract string

2006-01-10 Thread Whelan, Paul
Like so: cat abc.txt | cut -d, -f3 Thanks. -Original Message- From: Zhao Peng [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 10, 2006 11:51 AM To: gnhlug-discuss@mail.gnhlug.org Subject: extract string Hi Suppose that I have a file called abc.txt, which contains the following 5

extract string

2006-01-10 Thread Zhao Peng
Hi Suppose that I have a file called abc.txt, which contains the following 5 lines (columns are delimited by ",") "name","age","school" "jerry" ,"21","univ of Vermont" "jesse","28","Dartmouth college" "jack","18","univ of Penn" "john","20","univ of south Florida" My OS is RedHat Enterprise, h