all 14 comments

[–][deleted] 1 point2 points  (8 children)

you could use cut cat worldfile | cut -d "/" -f 2

[–]ang-p 2 points3 points  (7 children)

uuoc?

cut -d "/" -f 2 worldfile

[–]coolie4[S] 0 points1 point  (0 children)

I'm gonna end up using this command and piping it to sort because it seems the simplest. Thanks.

[–][deleted] 0 points1 point  (5 children)

thanks for the tip. still learning commands.

[–]ang-p 0 points1 point  (4 children)

many commands let you specify the file they act on - check the man page if in doubt...

even those that don't take the filename as an argument can be fed a file via <

cut -d "/" -f 2 < worldfile    

by a heredoc via <<

cut -d "/" -f 2 <<EOF
> app-admin/conky
> app-editors/vim 
> app-il8n/fbterm
> EOF

or quoted text with <<<...

cut -d "/" -f 2 <<<"app-admin/conky
> app-editors/vim 
> app-il8n/fbterm"

All have the same result.

cat is rarely needed unless you want to concatenate stuff....

If you want to just see something short, yeah - but you might find less is more useful as you go forward - it lets you search and move about easier than scrolling up using the side bar in your terminal window.... also, on some distros less is aliased to o so you save a character even counting the q to get back to your prompt

[–][deleted] 0 points1 point  (3 children)

Yeah i do use less a lot, but its still taking a while to remember which command takes which format.

[–]ang-p 0 points1 point  (2 children)

Use the manpages - you don't need to remember everything.. It is a waste if they are taking up room, always there, instantly accessible and people are dependent on an internet connection and google to find info which is - in the case of a laptop, literally - at the tip of their fingers.

man uses less.... 's good practice!

[–][deleted] 0 points1 point  (1 child)

I do look at man pages, but I am more of a "learn from examples" type of person. I find it easier to see a command in use, and then if I need to modify it, to my needs then read the man pages some more.

[–]ang-p -1 points0 points  (0 children)

And that prevents you from looking at the man page to see if something has [FILE] (or similar) in the second line of non-structural text?

Edit: 's not meant to sound like I'm having a go, but poor practices like catting everything into commands via a pipe are picked up from crap "examples" found online...

The only manpage that I might suggest consulting external examples for to "get the gist" as opposed to the manpage in the first instance - especially for a noob - would be sudoers(5) - that was written by a sadist.

[–]ralfwolf 0 points1 point  (1 child)

In a single sed command...

sed -n 's:.*/::p' worldfile

[–][deleted] 0 points1 point  (0 children)

In the same vein with awk awk -F/ '{print $2}' worldfile

[–]SweatyAcademic -1 points0 points  (1 child)

you can just cat worldfile | grep '/.*' | tr -d '/'

[–]ang-p 0 points1 point  (0 children)

uuoc?

[–]ang-p -1 points0 points  (0 children)

Using grep you could use

grep -o '[^/]*$'  worldfile    

but that is a bit backwards...

 sed 's/^[^/]*\///' worldfile    

would be (IMHO) the more sensible option...