Sponsored Content
Full Discussion: Copy part of a variable
Top Forums Shell Programming and Scripting Copy part of a variable Post 302369557 by Shellslave on Monday 9th of November 2009 04:07:20 AM
Old 11-09-2009
Copy part of a variable

Hi,

i was using a input file to get the last line of the file.But now i have stored
the values from the file to a variable and want the last line from the variable . Slightly confused on how to extract that data from the variable.

previous code,
Code:
 
cat input.txt
<TIME>00:15:48</TIME>
asderffgg
<TIME>15:15:20</TIME>
sdfrtghy
<TIME>22:14:40</TIME>
sderrthgh
<TIME>18:19:32</TIME>
sfrtryhbhgh
<TIME>16:15:48</TIME>
 
grep "<TIME>" input.txt > temp.txt
 
cat temp.txt
<TIME>00:15:48</TIME>
<TIME>15:15:20</TIME>
<TIME>22:14:40</TIME>
<TIME>18:19:32</TIME>
<TIME>16:15:48</TIME>
echo `tail -1 temp.txt` >temp.txt
 
o/p:
in the temp file i got <TIME>16:15:48</TIME>

now i dont want to use this temp file instead i want to put these in a variable and get the same output in that variable.
any help will be appreciated

---------- Post updated at 02:37 PM ---------- Previous update was at 02:29 PM ----------

Now i am trying to remove the temp file and use variable to do all the work done by temp file.

code now,
Code:
h=`grep "<TIME>" input.txt`
f=`echo $h|tail -1 `

this code is not working
i get
echo $h
<TIME>00:15:48</TIME> <TIME>15:15:20</TIME> <TIME>22:14:40</TIME><TIME>18:19:32</TIME> <TIME>16:15:48</TIME>

and also $f
<TIME>00:15:48</TIME> <TIME>15:15:20</TIME> <TIME>22:14:40</TIME><TIME>18:19:32</TIME> <TIME>16:15:48</TIME>
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies

2. Shell Programming and Scripting

Repacing part of string with a variable

I have following strings in a file DUPTASMTRMMBAL,20070416200704160117232101172321,,,,,,,@@@Y DUPTASMTRMMCON,20070416200704160127189901271899,,,,,,,@@@Y DUPTASMTRMMHG,,20070416200704160112051001120510,,,,,,,@@@Y What i need to do is replace the date 20070416 with anoth date which is stored in... (4 Replies)
Discussion started by: divz
4 Replies

3. Shell Programming and Scripting

Perl or Awk script to copy a part of text file.

Hi Gurus, I'm a total newbie to Perl and Awk scripting. Let me explain the scenario, there is a DB2 table with 5 columns and one of the column is a CLOB datatype containing XML. We need all the 4 columns but only a portion of string from the XML column. We decided to export DB2 table to a .del... (26 Replies)
Discussion started by: asandy1234
26 Replies

4. Shell Programming and Scripting

Variable of Content From Part of Other File

I may not being doing this description justice, but I'll give it a try. I created a mailx script; there will be several messages using the same script where the only difference is the content. So I figured I'd make the content of the message a variable retrieved from a separate file. I have five... (5 Replies)
Discussion started by: royarellano
5 Replies

5. Shell Programming and Scripting

How read the part of the string into a variable?

Hi, I'm using bash and brand new to shell script. I would like to do the following. I have a string which is "UPDATE=1.0". I would like to read the value "1.0" alone in a variable. i.e the things afer "=" How do I do that? Thanks, (1 Reply)
Discussion started by: scriptfriend
1 Replies

6. UNIX for Dummies Questions & Answers

Removing Part of a variable based on a pattern

Hi All, I am writing a script to work with files in a folder. The files are all in the following patterns (without quotes): "some filename - NxNN - the end.YYY" or "some filename - NNxNN - the end.YYY" Where N = a single number and YYY is the extension. Basically what I want... (5 Replies)
Discussion started by: sgtbobie
5 Replies

7. UNIX for Dummies Questions & Answers

Copy a part of file

Hi, I want to copy text between expressions ">bcr1" and ">bcr2" to another file. Any simple solutions? Thanks (4 Replies)
Discussion started by: alpesh
4 Replies

8. Shell Programming and Scripting

Using the part of a line as a variable?

Hello Friends, I need a command (or script line) that allows me to use of a part of line (given by me) as a variable. Let us assume the name of the command is MYCMD. When I type MYCMD fish://mfong@vhl.gov.nd/homefolder/hhk/ADS/ it must do the following job cd /homefolder/hhk/ADS/ ... (18 Replies)
Discussion started by: rpf
18 Replies

9. UNIX for Dummies Questions & Answers

Copy the last part since the file has been updated

Input File1 constatntly running and growing in size. My Program Erorr ddmmyy hh:mm:ss My Program Error **Port 123 terminated **ID PIN 12345 Comamnd Successful Command Terminated Command Successful Command Terminated **My Program Erorr ddmmyy hh:mm:ss My Program Error **Port 345... (3 Replies)
Discussion started by: eurouno
3 Replies

10. Shell Programming and Scripting

Copy part of file between two strings to another

I am a newbie to shell scripting I have a large log file , i need to work on the part of the log file for a particular date. Is there a way to find the first occurance of the date string and last occurance of the next day date date string and move this section to a new file. to explain it... (3 Replies)
Discussion started by: swayam123
3 Replies
TMPFILE(3)								 1								TMPFILE(3)

tmpfile - Creates a temporary file

SYNOPSIS
resource tmpfile (void ) DESCRIPTION
Creates a temporary file with a unique name in read-write (w+) mode and returns a file handle . The file is automatically removed when closed (for example, by calling fclose(3), or when there are no remaining references to the file handle returned by tmpfile(3)), or when the script ends. For details, consult your system documentation on the tmpfile(3) function, as well as the stdio.h header file. RETURN VALUES
Returns a file handle, similar to the one returned by fopen(3), for the new file or FALSE on failure. EXAMPLES
Example #1 tmpfile(3) example <?php $temp = tmpfile(); fwrite($temp, "writing to tempfile"); fseek($temp, 0); echo fread($temp, 1024); fclose($temp); // this removes the file ?> The above example will output: writing to tempfile SEE ALSO
tempnam(3), sys_get_temp_dir(3). PHP Documentation Group TMPFILE(3)
All times are GMT -4. The time now is 09:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy