scripting question

scripting question

Post by @ndre » Fri, 12 Jul 2002 22:28:43



Hi,

I've got a scripting question.
I've got the following files: NAME-access_log
NAME is different per file.
I want to have only NAME.

On linux the following works:
ls *-access_log |awk -F -access_log '{print $1}'

output:
NAME1
NAME2
NAME3
etc...

Unfortunatly, this doesn't work with solaris :-(
It just keeps printing
NAME1-access_log
NAME2-access_log
NAME3-access_log
etc...

Does anyone has an idea, how to solve this?

thanks in advance

Andree

 
 
 

scripting question

Post by John Howell » Fri, 12 Jul 2002 23:14:27



> Hi,

> I've got a scripting question.
> I've got the following files: NAME-access_log
> NAME is different per file.
> I want to have only NAME.

> On linux the following works:
> ls *-access_log |awk -F -access_log '{print $1}'

> output:
> NAME1
> NAME2
> NAME3
> etc...

> Unfortunatly, this doesn't work with solaris :-(
> It just keeps printing
> NAME1-access_log
> NAME2-access_log
> NAME3-access_log
> etc...

> Does anyone has an idea, how to solve this?

ls *-access_log | sed -e 's/-access_log//'

John Howells

 
 
 

scripting question

Post by Griff Miller I » Sat, 13 Jul 2002 02:32:09



> Hi,

> I've got a scripting question.
> I've got the following files: NAME-access_log
> NAME is different per file.
> I want to have only NAME.

> On linux the following works:
> ls *-access_log |awk -F -access_log '{print $1}'

> output:
> NAME1
> NAME2
> NAME3
> etc...

> Unfortunatly, this doesn't work with solaris :-(
> It just keeps printing
> NAME1-access_log
> NAME2-access_log
> NAME3-access_log
> etc...

> Does anyone has an idea, how to solve this?

> thanks in advance

> Andree

Use nawk .  The nawk -F flag works with RE's .

--
Griff Miller II                   |                                           |
Manager of Information Technology | "I need to be the owner of all of         |
Positron Corporation              |  the files in /usr/kvm."                  |

 
 
 

scripting question

Post by Mike Marsha » Sat, 13 Jul 2002 02:49:03


bonnieblue% ls
name1-access_log  name2-access_log  unrelatedfile
bonnieblue% ls *-access_log | awk -F- '{ print $1 }'
name1
name2
bonnieblue% uname -a
SunOS bonnieblue 5.8 Generic_108528-11 sun4u sparc SUNW,Ultra-5_10

-Mike     http://hubcap.clemson.edu/~hubcap

 
 
 

scripting question

Post by Didier Imbreck » Sat, 13 Jul 2002 17:09:22





> > Hi,

> > I've got a scripting question.
> > I've got the following files: NAME-access_log
> > NAME is different per file.
> > I want to have only NAME.

> > On linux the following works:
> > ls *-access_log |awk -F -access_log '{print $1}'

> > output:
> > NAME1
> > NAME2
> > NAME3
> > etc...

> > Unfortunatly, this doesn't work with solaris :-(
> > It just keeps printing
> > NAME1-access_log
> > NAME2-access_log
> > NAME3-access_log
> > etc...

> > Does anyone has an idea, how to solve this?

> > thanks in advance

> > Andree

> Use nawk .  The nawk -F flag works with RE's .

If you don't use the new awk /usr/bin/nawk and still using the old awk
/usr/bin/awk, your must change your command to
ls *-access_log|awk 'BEGIN{FS="-access_log"}{print $1}'

FS is for FieldSeparator the F in your command.

Didier

 
 
 

scripting question

Post by Wayne Polloc » Sun, 14 Jul 2002 01:36:46



> Hi,

> I've got a scripting question.
> I've got the following files: NAME-access_log
> NAME is different per file.
> I want to have only NAME.

> On linux the following works:
> ls *-access_log |awk -F -access_log '{print $1}'

> output:
> NAME1
> NAME2
> NAME3
> etc...

> Unfortunatly, this doesn't work with solaris :-(
> It just keeps printing
> NAME1-access_log
> NAME2-access_log
> NAME3-access_log
> etc...

> Does anyone has an idea, how to solve this?

> thanks in advance

> Andree

If you use ksh or bash you can save a process by using:

for i in *-access_log
do echo ${i%-access_log}
done

In the words of Larry Wall, "There's more than one way to do it!"

-Wayne

 
 
 

scripting question

Post by Kevin R. Pace » Sat, 20 Jul 2002 22:15:09



> Hi,

> I've got a scripting question.
> I've got the following files: NAME-access_log
> NAME is different per file.
> I want to have only NAME.

> On linux the following works:
> ls *-access_log |awk -F -access_log '{print $1}'

> output:
> NAME1
> NAME2
> NAME3
> etc...

> Unfortunatly, this doesn't work with solaris :-(
> It just keeps printing
> NAME1-access_log
> NAME2-access_log
> NAME3-access_log
> etc...

> Does anyone has an idea, how to solve this?

> thanks in advance

> Andree

Get rid of the space between "-F" and "-access_log"

-krp

 
 
 

1. A Solaris 8 (Bourne Shell) Scripting question, regarding a log rotation script

2. Problems with "make test" -- tcl8.0.4/SunOS 5.6/Solaris 2.6

3. Korn Shell Scripting Question, Restarting a script

4. Advice on making a history log

5. Shell script question, (2 questions)

6. ANSI feasure

7. ksh script question again

8. DFE530TX

9. chat script question

10. Shell Script Question

11. bourne shell script question re: for-in loop

12. bourne shell script question ...

13. A few simple shell and scripting questions