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
CREATE_MAKEFILE 						  [FIXME: manual]						   CREATE_MAKEFILE

NAME
create_makefile - Creates Makefile.in and Makefile from a Makefile.am SYNOPSIS
create_makefile [relativepath/Makefile] [relativepath] DESCRIPTION
create_makefile creates the Makefile.in and Makefile in a subdirectory containing a Makefile.am. This script saves time compared to re-running configure completely Note that you must supply the path to the desired MakefileMakefile.am (though the final /Makefile may be omitted). This script may be run from the toplevel directory (the one containing configure) or from one of it's subdirectories. If the source directory is different from the build directory (see the environment variables below), it will be assumed that the Makefile.am and Makefile.in belong beneath the source directory and that the Makefile belongs beneath the build directory. This utility is part of the KDE Software Development Kit. ENVIRONMENT
One of the following variables (but not both) should be set if the source directory is different from the build directory. If the build directory is simply a subdirectory of the source directory, the simpler variable OBJ_SUBDIR should be used. OBJ_SUBJDIR Indicates that the build directory is in the given subdirectory of the source directory. For instance, if the source directory is kdesdk and the build directory is kdesdk/obj-i386-linux, then OBJ_SUBDIR should be set to obj-i386-linux. OBJ_REPLACEMENT A sed expression that is used to transform the source directory into the build directory. For instance, if the source directory is ~/src/kdesdk and the build directory is ~/src/kdesdk-obj, then OBJ_REPLACEMENT should be set to s#kdesdk#kdesdk-obj#. SEE ALSO
create_makefiles(1) AUTHORS
create_makefile was written by David Faure<faure@kde.org> and others. This manual page was prepared by Ben Burton<bab@debian.org> for the Debian GNU/Linux system (but may be used by others). [FIXME: source] March 8, 2003 CREATE_MAKEFILE
All times are GMT -4. The time now is 03:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy