awk question.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

im using ls -l | xargs | awk '{what ever files here}'

im trying to get something that looks like this
2040 r-x 2 14:26 bin
3072 r-x 2 15:59 dev

ok so, the problem is that the first thing ls -l prints out is

total 624

I would like to undertand how to make awk or xargs skip this first line in its evaluation. or is there a way?

thanks

  1. Relevant commands, code, scripts, algorithms:

ls -l | xargs | awk

  1. The attempts at a solution (include all code and scripts):

several.

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

school = pima.edu
intro to unix =CSI137
instructor is B. Tucker

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

The default action of xargs (with no parameters) is to "echo" the output.

It generally doesn't make any sense just to echo what is already printed.

Assuming you're comfortable with everything else, just change your awk to remove the first (total ...) line:

ls -l | awk 'NR>1 { ..... }'

thanks.. been playing around with this. the line I have now is

ls -l / | grep '^d' | awk '{print $5, $1, $2, $8, $9}'

which give me pretty much the output I want but the fields are not lined up. like its missing some kind of a tab or something? I suspect there is an option in the that comes after print.. but i dont see one that lines up he fields.

almost there.

try

awk -F OFS="\t" ...

to make awk print tabs instead of spaces.

And if all else fails, you could use awk's printf to format the output however you like.

one last thing.. how would I save a cammand as a varible? I dont know how to explain better than that. I can write an example even tho I know this does not work. I know cause I tried :slight_smile: several different ways.. no joy

I would like a varible to hold the information from this command

ls - gko / | egrep '^' | wc -l

in simple terms;

n = ls - gko / | egrep '^' | wc -l # this displays the number of directorys in root
echo $n 

output would be
31

thanks lots

Use command substitution.

n=$(your_command_goes_here)

Use the back quote:

n=`ls -gko / | egrep '^' | wc -l #`

echo $n
75