Pic a value from a line at runtime


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pic a value from a line at runtime
# 1  
Old 07-02-2013
Pic a value from a line at runtime

Code:
BIP in report_one_acnt> **SUCCESSFUL** BILL 25895519 ACCOUNT 7615

hi i have a line above.. i need to pick the value 25895519 at runtime.

this number can be of different length but the number will always appear in this this line. and between the words BILL and ACCOUNT

**SUCCESSFUL** this is also constant in the line.

how can i pick this value and store in a variable
# 2  
Old 07-02-2013
You can use "sed" to manipulate the line. The following expression will pick up anything between "BILL" and "ACCOUNT":

Code:
echo "BIP in report_one_acnt> **SUCCESSFUL** BILL 25895519 ACCOUNT 7615" |\
sed 's/^.*BILL //; s/ ACCOUNT.*$//'

The first regexp cuts away everything before and including "BILL " (with a space following), the second cuts everything from " ACCOUNT" (with a leading blank) to the end of line, which leaves solely the number.

Still, this might have to be checked if it is indeed a number (for instance, "...BILL FOOBAR ACCOUNT..." might break whatever follows, because the extracted "FOOBAR" is NOT a number). You can do this by:

Code:
# catch the result in a variable
var="$( echo "BIP in report_one_acnt> **SUCCESSFUL** BILL 25895519 ACCOUNT 7615" |\
        sed 's/^.*BILL //; s/ ACCOUNT.*$//' \
      )

# test if "$var" contains only digits:
if [ -n "$(echo "$var" | sed 's/[0-9]//g)" ] ; then
     echo "$var is not a number"
else
     echo "$var is a number"
fi

I hope this helps.

bakunin
[/code]
# 3  
Old 07-02-2013
Quote:

Pic a value from a line at runtime


Code:
BIP in report_one_acnt> **SUCCESSFUL** BILL 25895519 ACCOUNT 7615

hi i have a line above.. i need to pick the value 25895519 at runtime.

this number can be of different length but the number will always appear in this this line. and between the words BILL and ACCOUNT

**SUCCESSFUL** this is also constant in the line.

how can i pick this value and store in a variable

Hello,

This solution will help you i case the field/column number is fix for the Digits required by you. Also lets say your data is stored in test11 file.

Code:
 
$ cat test11
BIP in report_one_acnt> **SUCCESSFUL** BILL 25895519 ACCOUNT 7615

$ awk '{print$6}' test11
25895519
$


Please let us knnow if we can help further on same.



Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 4  
Old 07-02-2013
THANKS FOR ALL YOUR HELP
I actually came up with my solution

Code:
BILL_REF=`grep "**SUCCESSFUL**" bip.txt | cut -d " " -f 6`

Is awk slower than grep?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wget help - unable to download pic

There is a website providing traffic camera images that gets updated every few minutes. My aim is to download the images over time to get a view of traffic conditions through the day. Website: CHECKPOINT.SG Image link, as taken from site source: http://www.checkpoint.sg/sg/2701 I tried... (2 Replies)
Discussion started by: Leion
2 Replies

2. Debian

After saving a pic, gimp should not be launched

Hi, i use a crunchbang-LINUX . The Problem: When i download and save a picture, the system automaticaly launches gimp. i tried to find a config file, were i can switch of this "gimp-start," but unfortunatelly i didnt find it. cat /etc/X11/default-display-manager /usr/bin/slim I'm also not... (2 Replies)
Discussion started by: IMPe
2 Replies

3. Shell Programming and Scripting

Runtime input

Hi all.. I have a command for example /abc/def/ghi.jkl Filename filename1. If I run this command, it will ask for y/N which I have to type manually. Now Im trying to automate it using shell script and input the y option. Please help me on doing this. Thanks in advance. ... (7 Replies)
Discussion started by: Sathya83aa
7 Replies

4. Ubuntu

setting pic folder for wallpapers

Hi, If I have folder with many pics, and I would like to use that folder for my desktop. But I don't want a specific pic, I want to replace every set of time the pic from the pics in that folder. How can I do that? In ubuntu of course. (0 Replies)
Discussion started by: programAngel
0 Replies

5. Shell Programming and Scripting

writing in a file's particular column number of every line during runtime

Given a particular line number and a corresponding column number, can i write something in the file during run time? For example x=1 and during runtime i want to write the value of x in column 100 of every line of a given file, then how shud that be done? Thanks (9 Replies)
Discussion started by: arindamlive
9 Replies

6. Solaris

SunFire v245 Environmental PIC micro controller fix

Hello All, We have a v245 that powered itself off for no reason. Searching around we discovered there is a bug were a temp error is being reported but doesnt actually exist, SUN released an EPIC update, the README is shown below but even after upgrading the ALOM to the latest v1.6.10 we do not... (8 Replies)
Discussion started by: Wez
8 Replies

7. Forum Support Area for Unregistered Users & Account Problems

where did you get your profile pic?

I like it! (1 Reply)
Discussion started by: jgentile
1 Replies

8. UNIX for Dummies Questions & Answers

Runtime Error...

My system did stay appears the error Run Time Library Error. What itīs? When the error appear, iīve to reboot my system and lost all I did. Is there the UNIX System problem? Please. I need help!!! (4 Replies)
Discussion started by: marpin
4 Replies

9. Shell Programming and Scripting

Getting Function Name At Runtime

Hi, Suppose I have a User define function get_abc in which I am using $0 to get the name of function. But when I call that function in any script, $0 will give the script name, not the function name. For example: Function: get_abc ------------------- get_abc( ){ echo $0 } Script:... (3 Replies)
Discussion started by: yeheyaansari
3 Replies
Login or Register to Ask a Question