Deleting carriage control from shell script variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting carriage control from shell script variable
# 1  
Old 08-05-2013
Deleting carriage control from shell script variable

I have a shell script variable called batch_id which contains the following value

Code:
export BTCH_ID=`cat /TEMPDATA/jelg0100_batchid_sorted.dat`
echo "BTCH_ID " = $BTCH_ID
BTCH_ID = 1389428^

This variable can be 7, 8 or 9 digits long, so I must capture only the true numerical value.

I am tryng to delete the ^ (carriage control), and I have tried treating the ^ as a character instead of carriage control. I have tried using sed, awk, echo command using the trailer delete, I have read all kinds of Q&As on the internet, etc., but nothing is working. This value comes from a file that was originally created using SUPRTOOL so I don't know if that has something to do with the problem. Does anyone have a suggestion?

Last edited by Scott; 08-05-2013 at 04:29 PM.. Reason: Code tags
# 2  
Old 08-05-2013
Please use code tags as required by forum rules!

Try to remove it upfront:
Code:
export BTCH_ID=$(tr -d '\r' < /TEMPDATA/jelg0100_batchid_sorted.dat)

# 3  
Old 08-05-2013
Thank you, but that still does not work:

Code:
echo "BTCH_ID " = $BTCH_ID
+ echo BTCH_ID = 1389428^
BTCH_ID = 1389428^

I copied/pasted your commands export BTCH_ID=$(tr -d '\r' < straight into the script, but the same result. The ^ still exists.

Any other suggestions would be appreciated.

Last edited by Scott; 08-05-2013 at 04:29 PM.. Reason: Code tags
# 4  
Old 08-05-2013
Please use code tags as required by forum rules!

Then there might be NO \r in the file... Pls post output of e.g. od /TEMPDATA/jelg0100_batchid_sorted.dat .
# 5  
Old 08-05-2013
Code:
suprtool  <<!EOSUPRTOOL
INPUT   TEMPDATA/jelg0100_batchid.dat, reclen 8,lf  
DEF BATCHID,1,8
EXT BATCHID
SORT BATCHID
DUPLICATE NONE KEYS
OUTPUT TEMPDATA/jelg0100_batchid_sorted.dat,LINK,lf
XEQ
EXIT
!EOSUPRTOOL
 
export BTCH_ID=$(tr -d '\r' < TEMPDATA/jelg0100_batchid_sorted.dat)

The contents of the above output file (jelg0100_batchid_sorted.dat) is:
Code:
1389428^

The batchid could actually be anywhere from 7-9 numbers long, but for testing purposes I'm just trying to work with 7 and 8 for now. As you can see when using 7, the ^ is included.
# 6  
Old 08-05-2013
Maybe try extracting numbers only:

Code:
export BTCH_ID=$(sed 's/[^0-9]//g' TEMPDATA/jelg0100_batchid_sorted.dat)
echo $BTCH_ID
1389428

# 7  
Old 08-05-2013
That worked! Thank you very much. I have spent hours today trying different combinations of sed, awk, unix commands, everything. I have never had a variable so difficult to manipulate.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing control back to the shell script

Hi All, I have a shell script(test_abc.sh) with the following shell commands, which are invoking the same shell script with different parameters. test_abc.sh . ./test.sh abc >> test.log . ./test.sh xyz >> test.log . ./test.sh pys >> test.log . ./test.sh abc >> test.log . . ... (4 Replies)
Discussion started by: dev.devil.1983
4 Replies

2. Shell Programming and Scripting

Control - M Scheduler is not able to pick my shell script

Hi, Below is a shell script that i made:- #!/bin/ksh #path=/opt/tibco/shared/adaptadores/SSCC/EVEREST/input/ if ; then echo "ZIP Exists and now Processing" for files in /opt/tibco/shared/adaptadores/SSCC/EVEREST/input/T010B04.* do unzip $files echo "Files Unzipped" echo $files... (4 Replies)
Discussion started by: mmtrexon
4 Replies

3. Post Here to Contact Site Administrators and Moderators

Control - M Scheduler is not able to pick my shell script

Hi, Below is a shell script that i made:- #!/bin/ksh #path=/opt/tibco/shared/adaptadores/SSCC/EVEREST/input/ if ; then echo "ZIP Exists and now Processing" for files in /opt/tibco/shared/adaptadores/SSCC/EVEREST/input/T010B04.* do unzip $files echo "Files Unzipped" echo $files... (1 Reply)
Discussion started by: mmtrexon
1 Replies

4. Shell Programming and Scripting

Version Control Through the Shell Script

Version Control Through the Shell Script Hi Guys, Apologize for the big request, please take some time and read it completely... This is Very important for me, and ur help is Very much Appriciated. I want to maintain the Version control to all my scripts running in Production server, I am... (6 Replies)
Discussion started by: Anji
6 Replies

5. Shell Programming and Scripting

Control browser from shell script

I have a browser running in a separate virtual terminal and would like to be able to send shortcut codes (e.g. ctrl+A) to the browser (and have it react) from a bash script in a separate virtual terminal. I need to keep the script in the separate virtual terminal. (2 Replies)
Discussion started by: slak0
2 Replies

6. Shell Programming and Scripting

Use a shell variable value in a control file via sqlloader

Dear, I must load a file in a table via sqlloader. I have also a column in this table which must contain the same value for all rows in this table. And this value is get from a shell script variable. Can you give me a sort example on how to use a shell script variable as a paramter in a CTL... (1 Reply)
Discussion started by: yeclota
1 Replies

7. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

8. Shell Programming and Scripting

How to Control Cronjobs using Shell Script??

Hi All, Now i am running the 3 oracle procedures one by one manually. Query: If 1st Procedure OUT_PUT is Success, then call 2nd Procedure. If 2nd Procedure OUT_PUT is Success, then call 3rd Procedure. If 1st Procedure is failed, then no need of calling the other ... (8 Replies)
Discussion started by: hanu_oracle
8 Replies

9. Shell Programming and Scripting

deleting 'carriage return' from string

hi there I'm getting a string from a sqlplus query, and I need to compare it with another string Problem here, is that the string i get from query brings a 'carriage return' with it, and comparing throws always false value. i need to delete all carriage retun charactres in string. how... (6 Replies)
Discussion started by: viko
6 Replies

10. Shell Programming and Scripting

control over shell script

Hi.. I have a perl program that uses "system" to execute a shell script called startengine. The script "startengine" itself calls a lot of other smaller scripts to setup the engine etc. It finally has to execute ./engine which is another shell script which is long and takes a long time to... (3 Replies)
Discussion started by: JLJ
3 Replies
Login or Register to Ask a Question