Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
What this does is "cuts" fields (-f) from the input file and puts them to stdout. You redirect to a file using the ">". -d specifies the delimiter, which in this case is the first parenthesis '(' and you wish only the first field prior to that delimiter.
Example:
Code:
$ cat 1.txt
Nicolaes Tulp (1593–1674), physician, surgeon and mayor of Amsterdam
Gustav de Vries (1866–1934), mathematician
Hugo de Vries (1848–1937), geneticist
$
$ cut -d ' ' -f1-2 1.txt
Nicolaes Tulp
Gustav de
Hugo de
@rtmistler
Thanks your advise. Working.
Almost good. I have 5 space characters before every name in my list and I would like to cut these, too. It is not shown my original post.
@rtmistler
Thanks your advise. Working.
Almost good. I have 5 space characters before every name in my list and I would like to cut these, too. It is not shown my original post.
Quote:
Originally Posted by crazy-yiuf
Then you can do:
Code:
sed 's/^[ ]*\([a-zA-Z ]*\)(.*/\1/1' list.txt
Sed's a pain, but extremely useful. Especially if you're a programmer and need to refactor array[0][1] to getArray(0,1), or something like that.
crazy-yiuf has it correct; however in the event that you encounter a TAB as opposed to spaces, you may wish to include a search for TAB in the regex:
the first one will remove the spaces before, the second one will remove ( and everything afterward. But remember it may not work properly if you have more than one (.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.