LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed script (https://www.linuxquestions.org/questions/linux-newbie-8/sed-script-4175524968/)

senbon 11-10-2014 10:21 AM

sed script
 
Hi,

I want to put my sed code into a script:

sed -n '/\(DREQ,\).*,0410/p' logs/2013/*

I want to make the 0410 into a variable declared outside of the script and also be able to run the script on any location choosen outside the script, any advice please?

TB0ne 11-10-2014 11:01 AM

Quote:

Originally Posted by senbon (Post 5267618)
Hi,
I want to put my sed code into a script:

sed -n '/\(DREQ,\).*,0410/p' logs/2013/*

I want to make the 0410 into a variable declared outside of the script and also be able to run the script on any location choosen outside the script, any advice please?

You'll have to pass the variable into the script SOMEHOW...the most obvious way would be using the "$1" variable when calling the script, and pass the 0410 (or whatever), as the first command-line argument.

Since you don't give us any details about the script or what you're trying to accomplish, or why you're using two scripts, it's hard to say.

dijetlo 11-10-2014 11:20 AM

I found this discussion to be very helpful after reading the original question.

senbon 11-12-2014 09:06 AM

Quote:

Originally Posted by TB0ne (Post 5267644)
You'll have to pass the variable into the script SOMEHOW...the most obvious way would be using the "$1" variable when calling the script, and pass the 0410 (or whatever), as the first command-line argument.

Since you don't give us any details about the script or what you're trying to accomplish, or why you're using two scripts, it's hard to say.

hi,

the script is used to look for 4 digit numbers in the following log file location SAC_LOGS/2014/*

My script now takes in the value from (read) value, see below. However i cannot make the location dynamic, i want to define the location outside of the script.

LOCATION=$1
echo -n 'Enter number to search '
read value
sed -n '/\(DREQ,\).*,"$value"/p' $LOCATION

senbon 11-13-2014 08:52 AM

Quote:

Originally Posted by senbon (Post 5268713)
hi,

the script is used to look for 4 digit numbers in the following log file location SAC_LOGS/2014/*

My script now takes in the value from (read) value, see below. However i cannot make the location dynamic, i want to define the location outside of the script.

LOCATION=$1
echo -n 'Enter number to search '
read value
sed -n '/\(DREQ,\).*,"$value"/p' $LOCATION

Any ideas?

TB0ne 11-13-2014 09:33 AM

Quote:

Originally Posted by senbon (Post 5268713)
hi,
the script is used to look for 4 digit numbers in the following log file location SAC_LOGS/2014/*

My script now takes in the value from (read) value, see below. However i cannot make the location dynamic, i want to define the location outside of the script.
Code:

LOCATION=$1
echo -n 'Enter number to search '
read value
sed -n '/\(DREQ,\).*,"$value"/p' $LOCATION


...and....
Quote:

Originally Posted by senbon
Any ideas?

Read the LQ Rules..don't bump your own thread asking for more help; this is a volunteer forum, and people answer when they can/want to. Unless you're providing more information, saying "Any ideas?" after less than 24 hours is fairly rude.

Second, did you read the link that dijetlo sent you? The one that has several examples on how to do what you're after?


All times are GMT -5. The time now is 04:40 PM.