Results 1 to 5 of 5
I have a file like in following format
Hello:World universe
Hello world universe hello
Hello world universe:hello
hello universe hello world hello
universe hello world
now I want to print ...
- 04-07-2008 #1Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
How print Last String of the Line in Shell
I have a file like in following format
Hello:World universe
Hello world universe hello
Hello world universe:hello
hello universe hello world hello
universe hello world
now I want to print last <string> of all lines, is there any way??
universe
hello
universe:hello
hello
world
thanksSwitched to Scripting
- 04-07-2008 #2
Yes, it's quite simple using awk:
Where <filename> is replaced with your fileCode:awk '{ print $NF }' <filename>Linux User #453176
- 04-07-2008 #3Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
Thanks, now I am facing some problem, if u can help me.
i am getting trailing line, how can I remove that, see below
$test = ssh hostname cat /proc/cpuinfo |grep -i 'model name'
echo "$test"
(standard input):model name : Intel(R) XEON(TM) CPU 2.40GHz
<trailing line>
And when I am checking value in variable, nothing is there
if [ -n $test ]; then
echo "$test"
else
echo "Error"
fi
but nothing is happening, even else is also not executingSwitched to Scripting
- 04-08-2008 #4
You need to use some quotes. Try:
The quotes I've used can be found by using shift and the key above the tab key.Code:$test = `ssh hostname cat /proc/cpuinfo |grep -i 'model name'` echo "$test"
Linux User #453176
- 04-08-2008 #5


Reply With Quote
