![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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> |
|
|||
|
this code works in bash... Code:
f=$(grep "<TIME>" input.txt | tail -1) Code:
echo $f <TIME>16:15:48</TIME> |
| Bits Awarded / Charged to protocomm for this Post | |||
| Date | User | Comment | Amount |
| 11-09-2009 | Anonymous | Thanks protocomm | 100 |
|
|||
|
Hey thanks this code works equally good.
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl or Awk script to copy a part of text file. | asandy1234 | Shell Programming and Scripting | 26 | 11-06-2009 12:17 PM |
| Set specific part in command output into variable | orit | Shell Programming and Scripting | 7 | 08-16-2008 11:34 AM |
| direction symbol in a variable as part of the command | peterloo | Shell Programming and Scripting | 5 | 12-06-2007 07:25 PM |
| Repacing part of string with a variable | divz | Shell Programming and Scripting | 4 | 07-19-2007 02:09 AM |
| ksh: A part of variable A's name is inside of variable B, how to update A? | pa3be | Shell Programming and Scripting | 4 | 03-30-2005 12:29 PM |