- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- c shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2002 09:27 PM
12-14-2002 09:27 PM
c shell script
Please help a beginner with a c shell script... the requirement is:
the script finds a specified string in each line of a file. I know that the following command works:
grep the_string the_file
How can I reach the same result in a c shell?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2002 10:38 PM
12-15-2002 10:38 PM
Re: c shell script
I don't see the problem:
------------------------
#!/bin/csh
grep the_string the_file
-------------------------
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2002 01:24 AM
12-16-2002 01:24 AM
Re: c shell script
##########################
#!/usr/bin/sh
AFILE='/tmp/yourfile'
grep "hello there" $AFILE
##########################
Chuck J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2002 04:23 AM
12-16-2002 04:23 AM
Re: c shell script
There are several ways to do a pattern search in unix script. You can put any of these commands in a file, then execute the file as a script:
grep pattern file
sed -n /pattern/p file
awk ' /pattern/ { print $0 } ' file
All three of the above commands give the same output, and all three can be put in a file to execute.
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2002 04:45 AM
12-16-2002 04:45 AM
Re: c shell script
Putting the grep statement in a script is a no brainer, but what is probably more important is what you want to do when you "FIND" the string in the_file ???
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2002 09:09 AM
12-16-2002 09:09 AM
Re: c shell script
In both of your questions, you are asked to write a "wrapper" script. This is also very basic scripting.
First, Borne and Korne shell have C like variable setting.
I.E.
I=1
NAME="john"
C-shell uses more basic like language.
I.E.
set I=1
set NAME="john"
In the shell, you need to know what the STDARGS is, and how to use it. Borne/Korn shell use stdargs differently than C-Shell.
You also need to look at the return value from your command to know if the command failed, or your string does not exist.
So the logic you need is to do this. Look for 2 arguments: filename and search_string.
1. Process input and look for entry of both arguments.
2 strings=continue
less than 2 strings=exit with error.
2. test to see if string 1 or string 2 is a filename. Hint: if ( -f "name") ; endif will test to see if name is a file.
3. use argument not a file with grep on the file.
Look at the return code from grep.
If you have matching strings, they will print to stdout unless you specify otherwize. If grep returns a 0, and no lines then grep was fine, but nothing was found. If grep returns anything greater than 0, then grep failed.
While many here including myself could write your assignment for you, it would be much better for you to learn and do it on your own.
All of the information needed for this work can be found in "Unix in a Nutshell", published by O'Reilly and Associates. There are sections for basic Borne/Korn and C-Shell scripting. You may have to read 2-4 pages in the C-Shell section to do this script.
Regards,
Shannon