|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | 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 | Display Modes |
|
#1
|
|||
|
|||
|
Retrieving values from a line in text file
Hi, I am new to Unix/ksh script and will like to check how do I retrieve just the count of '258' in the last line in a text file ? There will be this "TRL" appended with number of count at the last line in a text file . Code:
TRL0000000258 Code:
var=`grep 'TRL' $HOME/folder/test.txt | wc -l` How do i substr and get the last 10 values into a variable ? Appreicate anyone who can help me . Thank You. Last edited by Scrutinizer; 01-09-2013 at 05:27 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Can you post the input file? ---------- Post updated at 05:54 AM ---------- Previous update was at 05:38 AM ---------- I think you are excepting this one... Code:
echo "TRL44440000000258"|awk '{ print substr( $1, length($1) - 9, length($1) ) }' |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Try: Code:
var=$(tail -1 infile)
var=${var#TRL}Code:
var=$(sed -n '$s/TRL//p' infile) |
|
#4
|
|||
|
|||
|
Input file : Code:
AAAAAAAAAAAAAAAA BBBBBBBBBBBBBBBB CCCCCCCCCCCCCCCC TRL0000000258 command : Code:
awk ' /^TRL/ {sub(/TRL/, "") ; print } ' fileoutput : Code:
0000000258 |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Code:
awk '/^TRL/{sub(/TRL0+/,"")}1' test.txt |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Yet another way... Code:
echo TRL0000000258 | awk '{gsub("[^0-9]", "");print $0+0}' |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
try also (using Scrutinizer's sed example) for eliminating leading non valid chars for numbers: Code:
var=$(sed -n '$s/^[^1-9]*//p' infile) |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Converting filenames from julian day to yyyy-mm-dd and retrieving weekly mean values | ida1215 | Shell Programming and Scripting | 3 | 02-14-2012 05:09 AM |
| Retrieving values from the oracle table | milink | Shell Programming and Scripting | 8 | 12-09-2010 06:09 AM |
| Retrieving values from tab-delimited file in unix script | akashtcs | Shell Programming and Scripting | 4 | 08-27-2009 08:15 AM |
| Problem with retrieving values from properties file | sailaja_80 | Shell Programming and Scripting | 2 | 08-21-2009 03:06 PM |
| Retrieving random numbers out of a text file | nistleloy | UNIX for Dummies Questions & Answers | 13 | 12-14-2008 03:28 PM |
|
|