LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-10-2014, 11:21 AM   #1
senbon
LQ Newbie
 
Registered: Oct 2013
Posts: 19

Rep: Reputation: Disabled
Smile 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?
 
Old 11-10-2014, 12:01 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by senbon View Post
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.
 
Old 11-10-2014, 12:20 PM   #3
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,307
Blog Entries: 2

Rep: Reputation: Disabled
I found this discussion to be very helpful after reading the original question.
 
Old 11-12-2014, 10:06 AM   #4
senbon
LQ Newbie
 
Registered: Oct 2013
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
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
 
Old 11-13-2014, 09:52 AM   #5
senbon
LQ Newbie
 
Registered: Oct 2013
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by senbon View Post
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?
 
Old 11-13-2014, 10:33 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by senbon View Post
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?
 
  


Reply

Tags
sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with sed script newtofedora1 Fedora 4 04-17-2011 09:50 AM
sed script help scriptblues Linux - Newbie 16 06-17-2009 08:05 AM
script with sed emetib Linux - General 3 05-04-2009 02:58 PM
Sed script help genderbender Programming 4 05-04-2008 05:38 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 12:36 PM


All times are GMT -5. The time now is 08:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration