Re: print from a field to EOL
- From: "William James" <w_a_x_man@xxxxxxxxx>
- Date: 23 May 2006 11:37:35 -0700
Chris F.A. Johnson wrote:
On 2006-05-23, Harlan Grove wrote:
kpcamp wrote...
Ok I am trying to create a file from output field "3" and "9 to EOL"
while read line;do
ls -ltr "${line}" |awk {'print$3":"$9'} #Need to have $9 to EOL
done < $file
This really belongs in comp.unix.shell. Followup set.
while read line;do
ls -ltr "${line}"
done < "$file" | tr -s ' ' | cut -d ' ' -f3,9-
Or:
IFS='
'
ls -ltr $( cat "$file" ) | tr -s ' ' | cut -d ' ' -f3,9-
...
Since you're dealing with ls output, your fields are fixed length.
Modern versions of ls do not produce fixed-length fields; they
produce whitespace-separated fields. The actual width of any field
(except the last) is determined by the longest entry in the field.
Use substr to get the substring of $0 beginning at the first
character of $9 and print that rather than $9.
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
ruby -ane 'puts $F.values_at(2,8..-1).join(" ")'
.
- Prev by Date: Re: How to enforce the "more" command
- Next by Date: Re: How to enforce the "more" command
- Previous by thread: Remvoing Empty Directories
- Next by thread: editing file name using command line argument.
- Index(es):
Relevant Pages
|