Re: print from a field to EOL



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(" ")'

.



Relevant Pages

  • Re: print from a field to EOL
    ... On 2006-05-23, Harlan Grove wrote: ... This really belongs in comp.unix.shell. ... Followup set. ... Shell Scripting Recipes: ...
    (comp.lang.awk)
  • Re: Cowboys sign Fabini
    ... That and they had a better replacement waiting in the wings. ... I also think the defenses are dealing better with Johnson, ...
    (alt.sports.football.pro.ne-patriots)
  • Re: A very simple question (I think!)
    ... > I am dealing with the following equation: ... > or belongs to a familly that has a name then any ... > background information would be really appreciated! ... Prev by Date: ...
    (sci.math)
  • A very simple question (I think!)
    ... I am dealing with the following equation: ... or belongs to a familly that has a name then any ... background information would be really appreciated! ... Prev by Date: ...
    (sci.math)
  • Re: om (on music): Robert Johnson
    ... you might also enjoy these posts about Mr. Johnson and dealing with the ... devil if you missed them ... Prev by Date: ...
    (alt.guitar.amps)