Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Help using combining variables with sed command (RHEL 7) Post 303043298 by isey78 on Thursday 23rd of January 2020 11:01:35 AM
Old 01-23-2020
Help using combining variables with sed command (RHEL 7)

Here is the whole script, very simple, but I am just learning

Code:
ROK_NO=$1
RPT=/tmp/test
sed -E '/^SELECT/ s/(.{23}).{8}/\1'"$ROK_NO"' /' $RPT
echo $RPT

When I run this I get

Code:
$ bash rok.sh 2388085
: No such file or directory
/tmp/test

When I type the command in console, it works (so I know there is a file there)

Code:
sed -E '/^SELECT/ s/(.{23}).{7}/\12388099 /' /tmp/test

Here is what the test file looks like before
Code:
SELECT:  ROK_NUMBER EQ 2388090

Here is what it looks like after
Code:
SELECT:  ROK_NUMBER EQ 2388099

That great but I want to use a script so I pass that number as an argument and use the $RPT variable? I'm sure it's something to do with the characters in the sed command and how I'm incorrectly using " vs ' but I cannot figure it out after hours of fiddling :/

Last edited by Scrutinizer; 01-23-2020 at 01:16 PM.. Reason: Additional code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

assigning variables in sed command

I need to assign a variable within a variable in a sed command. I tried doing the following in c shell. set left = 1 set right = 2 set segment = qwerty sed -n -e "/$segment{$left}/,/$segment{$right}/p" file.txt what is wrong with this syntax? (3 Replies)
Discussion started by: wxornot
3 Replies

2. UNIX for Dummies Questions & Answers

sed command not work with variables?

I am trying to write a simple script which will take a variable with sed to take a line out of a text and display it #!/bin/sh exec 3<list while read list<&3 do echo $list sed -n '$list p'<list2 done this does not work, yet when I replace the $list variable from the sed command and... (1 Reply)
Discussion started by: MaestroRage
1 Replies

3. Shell Programming and Scripting

sed: command garbled - when executed with $variables

I have got a file job_tree.lst , which contains 1 line as below $ cat job_tree.lst ABC_D_EQ_XXXXX_YYYY_PRD_UX 05/08/2009 05:47 05/08/2009 05:50 IN 13412850/0 I want to get a child job string 3 characters offset from the parent job string (i.e. ABC_D_EQ_XXXXX_YYYY_PRD_UX 05/08/2009... (4 Replies)
Discussion started by: Armaan_S
4 Replies

4. Shell Programming and Scripting

Combining two variables in ksh

I can't believe I can't figure this out... given this code: CARS_DATA_LIST=`cat /tmp/file1 | awk '{print $1}' ` FMSA_DATA_LIST=`cat /tmp/file2 | awk '{print $1}' ` The value of each of the above variables is: CARS = a b c d e f g FMSA = a b c q r s I want to declare a third... (8 Replies)
Discussion started by: Shoeless_Mike
8 Replies

5. Shell Programming and Scripting

Problem combining two variables into one

Hello, I have a problem combining two variables into one. I did the following: in my env variables i had set PATH_DESTINATION_1=/root/path_one PATH_DESTINATION_2=/root/path_two #!/usr/bin/ksh count=1 count_path=2 while do (3 Replies)
Discussion started by: Eraser
3 Replies

6. Shell Programming and Scripting

sed command using variables in shell script

hi guys, The following command doesn't seem to work in my shell script: tag=$(sed -n '/${line}/ s/.*\.*/\1/p' myfile.txt) When i replace the ${line} with an actual value, it works fine. So, how do i use the ${line} in this sed command? Thanks in advance, Zaff (2 Replies)
Discussion started by: zaff
2 Replies

7. Shell Programming and Scripting

Variables in SED command

Hi all, I want write a script to display 5rows at times from a input file. my out like: echo " display started" r1 r2 r3 r4 r5 ... Some action items... again i need next 5 lines. can you please advise. (2 Replies)
Discussion started by: koti_rama
2 Replies

8. Shell Programming and Scripting

Combining multiple variables into new variable

Hello, I am a new joiner to the forum, and have what i hope is a simple question, however I can't seem to find the answer so maybe it is not available within bash scripting. I intend to use the below script to archive files from multiple directories at once by using a loop, and a variable (n)... (10 Replies)
Discussion started by: dring
10 Replies

9. Red Hat

Does RHEL 5 provide a command to collect RHEL system log in single compress file?

Hi, I heard a command that can collect all RHEL 5 log in a single compress file before I forget. Does any body know...What the command is ? Thanks. (4 Replies)
Discussion started by: nnnnnnine
4 Replies

10. Shell Programming and Scripting

How to use variables in 'sed' append command?

HELLO!! I'm trying to pass a variable with in the 'sed' command (which would add some piece of code to file at a particular line). We can use sed '{line-number}a\ alfjaljf\ aslfjsfsjafl\ adlfjaf\' file.txt If file.txt is Now, I would like to add the parameter 'lmn' after... (1 Reply)
Discussion started by: mjavalkar
1 Replies
DEVSCRIPTS.CONF(5)						File Formats Manual						DEVSCRIPTS.CONF(5)

NAME
devscripts.conf - configuration file for the devscripts package DESCRIPTION
The devscripts package provides a collection of scripts which may be of use to Debian developers and others wishing to build Debian pack- ages. Many of these have options which can be configured on a system-wide and per-user basis. Every script in the devscripts package which makes use of values from these configuration files describes the specific settings recognised in its own manpage. (For a list of the scripts, either see /usr/share/doc/devscripts/README.gz or look at the output of dpkg -L devscripts | grep /usr/bin.) The two configuration files are /etc/devscripts.conf for system-wide defaults and ~/.devscripts for per-user settings. They are written with bash(1) syntax, but should only have comments and simple variable assignments in them; they are both sourced (if present) by many of the devscripts scripts. Variables corresponding to simple switches should have one of the values yes and no; any other setting is regarded as equivalent to the default setting. All variable names are written in uppercase, and begin with the script name. Package-wide variables begin with "DEVSCRIPTS", and are listed below, as well as in the relevant manpages. For a list of all of the available options variables, along with their default settings, see the example configuration file /usr/share/doc/devscripts/devscripts.conf.ex. This is copied to /etc/devscripts.conf when the devscripts package is first installed. Information about configuration options introduced in newer versions of the package will be appended to /etc/devscripts.conf when the pack- age is upgraded. Every script which reads the configuration files can be forced to ignore them by using --no-conf as the first command-line option. PACKAGE-WIDE VARIABLES The currently recognised package-wide variables are: DEVSCRIPTS_CHECK_DIRNAME_LEVEL, DEVSCRIPTS_CHECK_DIRNAME_REGEX These variables control scripts which change directory to find a debian/changelog file or suchlike, and some other miscellaneous cases. In order to prevent unwanted, even possibly dangerous, behaviour, these variables control when actions will be performed. The scripts which currently make use of these variables are: debc, debchange/dch, debclean, debi, debrelease, debuild and uscan, but this list may change with time (and I may not remember to update this manpage). Please see the manpages of individual scripts for details of the specific behaviour for each script. SEE ALSO
devscripts(1) and /usr/share/doc/devscripts/README.gz. AUTHOR
This manpage was written for the devscripts package by the package maintainer Julian Gilbey <jdg@debian.org>. DEBIAN
Debian Utilities DEVSCRIPTS.CONF(5)
All times are GMT -4. The time now is 05:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy