![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| getopts alternative? | krishmaths | Shell Programming and Scripting | 3 | 04-05-2008 10:43 PM |
| Alternative to date +%s | Data469 | HP-UX | 6 | 03-31-2008 12:28 PM |
| Using awk (or an alternative) | michaeltravisuk | Shell Programming and Scripting | 5 | 03-08-2007 08:37 PM |
| .NET Alternative | goon12 | UNIX for Dummies Questions & Answers | 3 | 04-06-2005 09:07 AM |
| loop alternative? | apalex | Shell Programming and Scripting | 2 | 05-02-2002 09:47 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
I'm trying the following as i wish to get the last field in a report containing several fields, each line can have more fields than the previous, so I tried
rvwords=`echo $rvstatus |wc -w` rvstat=`echo $rvstatus |cut -f $rvwords` but it prints the whole variable contents of $rvstatus rather than just the seventh field, there are no delimeters (other than spaces / tabs) in the line, which would read along the lines of 0 1111 my file 102.00 1003.00 2.99 1 2222 my own file 111.00 112.98 200.10 ... Thanks in anticipation |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
rvstat=`echo $rvstatus | nawk '{print $NF}'`
or with sed: rvstat=`echo $rvstatus | sed -e 's/.* \([^ ][^ ]*\)[ ]*$/\1/'` Last edited by vgersh99; 03-01-2005 at 11:39 AM. |
|
#3
|
||||
|
||||
|
Try this ....
Code:
$ echo "0 1111 my file 102.00 1003.00 2.99" | cut -d" " -f 7 2.99 Code:
$ echo "0 1111 my file 102.00 1003.00 2.99" | tr -s " " | cut -d" " -f 7 2.99 |
|
#4
|
|||
|
|||
|
Try as with awk as,
Code:
awk ' { print $NF }' <filename>
or
sed 's/.*[ ]\(.*\)$/\1/' <filename>
|
|
#5
|
|||
|
|||
|
Quote:
|
|
#6
|
||||
|
||||
|
Quote:
Code:
# 4th AND 5th from last
rvstat=`echo $rvstatus | nawk '{print $(NF-4), $(NF-5)}'`
# 4th from last
rvstat=`echo $rvstatus | nawk '{print $(NF-4)}'`
|
|
#7
|
|||
|
|||
|
Quote:
|
|||
| Google The UNIX and Linux Forums |