sed script to read only columns 4 to 6 in output database
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi,
thanks but what i have to do so that output will come proper aligned.
what i get is
root 355 Feb
root 93 Feb
root 171830 Feb
root 70 Feb
root 804 Feb
which is not aligned to columns starting at some distance
hi,
thanks but what i have to do so that output will come proper aligned.
what i get is
root 355 Feb
root 93 Feb
root 171830 Feb
root 70 Feb
root 804 Feb
which is not aligned to columns starting at some distance
next time you can elaborate better your question in the first post..
the following quick and dirty code ..
Code:
awk '
begin
{
printf("%6s %6s %6s",$4,$5,$6)
} ' $some_file
will format the output for you...
regards,
slackie1000
You can remove the $somefile from the end if you want to pipe the output of the ls command directly to the awk command.
Another way of extracting certain columns from ls -l is to use the "cut" command.
example:
ls -ld * | tr -s ' ' | cut -d' ' -f5,8 --output-delimiter=" "
( note: for the output delimiter I pressed CNTRL-v [TAB] )
The tr command removes duplicate spaces between each field. The cut command then extracts fields 5 and 8. A tab is used in between the size and name on the output. The cut and tr commands are a lot smaller than awk, 34k vs 226k but my example uses 3 commands instead of two. Using a wildcard at the end of the ls command avoids the initial total line.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.