LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-09-2015, 06:02 AM   #1
slowerogue
Member
 
Registered: Oct 2012
Posts: 96

Rep: Reputation: Disabled
using cut -d" " to cut out the string before, not after


Hi Guys,
i have this
Code:
uid=0(root) gid=0(root)
i would like to have the word "root" only from the first field, and later from the second field

i use the command
Code:
[root@v1-6 ~]# cat test-uid |cut -d"(" -f1
brms2
uid=0

[root@v1-6 ~]# cat test-uid |cut -d")" -f1
brms2
uid=0(root
it cut the word after the -d, how can i make it to cut the word BEFORE the -d

expected should be:
cut -d"(" -f1
root)

then i can proceed to eliminate the ) later on.
hope this is not confusing you guys

Thanks,
 
Old 01-09-2015, 06:19 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
What about this:
Code:
cat test-uid |cut -d"(" -f2
That produces this:
Code:
$ cat test-uid |cut -d"(" -f2
root) gid=0
which is a bit closer to what you want.
jdk
 
1 members found this post helpful.
Old 01-09-2015, 06:25 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,797

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
cut -d"(" -f2 | cut -d")" -f1
but I would use awk:
awk 'BEGIN{FS="[()]"} {print $2}'
 
1 members found this post helpful.
Old 01-09-2015, 06:37 AM   #4
slowerogue
Member
 
Registered: Oct 2012
Posts: 96

Original Poster
Rep: Reputation: Disabled
Hi Guys,
Thanks alot man, solved already, i still got other question but its a different thing.
so i think would open another one.
Thanks,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: "Internet's Own Boy" pays tribute to hacker who cut his life short LXer Syndicated Linux News 0 06-28-2014 12:18 AM
unpredictable "delete" "move to trash" or "cut" file menu option dorianrenato Linux - General 3 11-28-2011 07:41 PM
Trying to use cut command to limit "excess text" from a file. Hank The Tank Linux - Newbie 2 02-24-2011 07:12 PM
Power-cut. If try pinging, get "connect: Network is unreachable" Azazwa Linux - Newbie 2 05-06-2009 01:35 AM
bash: "cut" and "case" help please tredegar Linux - Newbie 14 06-26-2008 05:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration