Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My simple grep script hangs!! :-(

Status
Not open for further replies.

bondtrails

Technical User
Nov 19, 2002
31
US
I try running this in super simple script in OS X, but it hangs..WHASSUP??

#!/bin/sh

# source and target directories
SOURCE_DIR='/Volumes/data_grp/HR/HROne/HROneDataWarehouse/Business Requirements/Data Management/Job Code Processing/NAM - Raw Source'
TARGET_DIR='/Volumes/data_grp/HR/HROne/HROneDataWarehouse/Business Requirements/Data Management/Job Code Processing'

# file to get
SOURCE_FILE=NAM_20021120.dat

# file to save as
TARGET_FILE=PS_JOBCODE_TBL_20021120.txt

# data records to get
DATA_RECS=PS_JOBCODE_TBL

# command to issue
COMMAND=grep

# initiate extract
$COMMAND "$DATA_RECS $SOURCE_DIR/$SOURCE_FILE > $TARGET_DIR/$TARGET_FILE"

After running this script, it just sits there for hours on end--it shouldn't take more than 4 minutes to run!! (That's how long it takes to run via the command line)
 
$COMMAND "$DATA_RECS" $SOURCE_DIR/$SOURCE_FILE > $TARGET_DIR/$TARGET_FILE vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hey thanks Vlad!!
Can you tell this newbie why my original script failed? I thought that putting double-quotes around the whole expression would expand the parameters properly.

Thanks for your help!!

--Bondster!!
 
Bondtrails:

Your original command didn't work because the shell was confused by the quotes. If you'd placed eval in front of your command:

eval $COMMAND &quot;$DATA_RECS $SOURCE_DIR/$SOURCE_FILE > $TARGET_DIR/$TARGET_FILE&quot;

From solaris man pages:

eval reads its arguments as input to the shell and executes
the resulting command(s). This is usually used to execute
commands generated as the result of command or variable sub-
stitution.

I'd use Vlad's solution if you're not creating command strings.

Regards,

Ed
 
sorry for being late [again].
I couldn't have said it better - thanks, Ed vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Vlad:

You're not late very often -), but you're welcome.

Ed
 
Hey Vlad / Ed,
thanks for your input. I tried your suggestion:
($COMMAND &quot;$DATA_RECS&quot; $SOURCE_DIR/$SOURCE_FILE > $TARGET_DIR/$TARGET_FILE)

and I am getting the message:
./script.sh: <long winded target directory/target file>: No such file or directory

This makes no sense because the target directory does exist. And it shouldn't matter if the target file exists or not because that's what I want to create from grep.

Any ideas??

--Bondster!!
P.S. script.sh is the name of my script
 
your TARGET_DIR contains SPACES:

TARGET_DIR='/Volumes/data_grp/HR/HROne/HROneDataWarehouse/Business Requirements/Data Management/Job Code Processing'

The rule of thumb is to QUOTE anything that can contains spaces so that the surrounding shell does NOT interpret it as &quot;space separated&quot; arguments.

Here's the mod to try:

$COMMAND &quot;$DATA_RECS&quot; &quot;$SOURCE_DIR&quot;/&quot;$SOURCE_FILE&quot; > &quot;$TARGET_DIR&quot;/&quot;$TARGET_FILE&quot;
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
ah!!!
I figured it out!!! Actually, by way of the brute force method (trying every possible quote combination) I got it to work. But lo and behold, I log on to tek-tips and vlad already had the solution--geez I feel pretty slow today

Vlad, thanks for the help! This worked for me too:
$COMMAND $DATA_RECS &quot;$SOURCE_DIR/$SOURCE_FILE&quot; > $TARGET_DIR/$TARGET_FILE

Geez, and the tutorials make the quoting features of unix seem so simple. I didn't think it could get so complex!! (seems that way for a newbie)

--Bondster!!
 
once you &quot;get a hang&quot; of it..... well... you know the rest...

good luck vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top