awk trailing character removal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk trailing character removal
# 1  
Old 06-26-2013
awk trailing character removal

Hi,

The command -
Code:
id | awk '{print $1}'

- returns the following:
Code:
uid=9028(luke)

What do I need to further that awk so that I only have "
Code:
luke

", I want to set this as a variable.

Thanks in advance,
Lukas.

P.S: I've come up with:
Code:
USER1=`id | awk F'(' '{print $2}' | awk -F')' '{print $1}'`

This returns, "luke" but is there a better way of getting the same result?

Last edited by Scrutinizer; 06-27-2013 at 03:09 PM.. Reason: Please use code tags; further code tags
# 2  
Old 06-26-2013
try..

Code:
 
id|awk -F"[()]" '{gsub(/[0-9]/,"",$2);{print $2}}'

This User Gave Thanks to vidyadhar85 For This Post:
# 3  
Old 06-26-2013
Try
Code:
id -un

Not sure if this works with your version.
# 4  
Old 06-26-2013
@vidyadhar85, I guess that gsub function is not really required:
Code:
id | awk -F'[()]' '{print $2}'

# 5  
Old 06-27-2013
There might even be user names with numbers in them; that gsub would spoil them...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removal Extended ASCII using awk

Hi All, I am trying to remove (SELECTIVE - passed as argument) Extended ASCII using Awk based on adhoc basis. Can you please let me know how to do it. I have to implement this using awk only. Thanks & Regads (14 Replies)
Discussion started by: tostay2003
14 Replies

2. UNIX for Dummies Questions & Answers

awk string removal

Hi, I am trying to remove a string ".var" using the below command but it's not working as expected, when I execute this in the command prompt using the echo it's working fine , please let me know where I am doing it wrong. UYRD=$FILE_$timestamp.csv | awk '{gsub(".var", "");print}' # this is... (6 Replies)
Discussion started by: shruthidwh
6 Replies

3. Shell Programming and Scripting

Control m Character removal shell script

can anyone share script for how to remove control m character (1 Reply)
Discussion started by: pw227j
1 Replies

4. Shell Programming and Scripting

sed help with character removal

Hello I've got a string of text with a number in pence, e.g. 0.52p, I need to remove the 'p' so that it just reads 0.52 without of course removing all the other 'p' characters. Many thanks (1 Reply)
Discussion started by: mrpugster
1 Replies

5. OS X (Apple)

vi and special character removal

To the group, when I copy text from a web page that has the below java code , and then do the set list command in the vi editor, I see the $ symbol at the end of each line. I have searched the internet looking for a way to remove this from the file since it will not compile without errors..Please... (6 Replies)
Discussion started by: smartino
6 Replies

6. Shell Programming and Scripting

any savant ? using AWK/SED to remove newline character between two strings : conditional removal

I'd like to remove (do a pattern or precise replacement - this I can handle in SED using Regex ) ---AFTER THE 1ST Occurrence ( i.e. on the 2nd occurrence - from the 2nd to fourth occurance ) of a specific string : type 1 -- After the 1st occurrence of 1 string1 till the 1st occurrence of... (4 Replies)
Discussion started by: sieger007
4 Replies

7. Shell Programming and Scripting

stdout to file or character device with trailing slash

I have an interesting one for the gurus out there that may have an idea as to why this is happening. We're currently migrating from Solaris 9 to Solaris 10 and we've run into a very strange issue. There are a bunch of shell scripts people have written throughout a directory that are used for... (4 Replies)
Discussion started by: dcarrion87
4 Replies

8. Shell Programming and Scripting

Removal of new line character in double quotes

Hi, Could you please help me in removal of newline chracter present in between the double quotes and replacing it with space. For example ... Every field is wrapped with double quotes with comma delimiter, so I need to travese from first double quote occerence to till second double... (7 Replies)
Discussion started by: vsairam
7 Replies

9. Shell Programming and Scripting

Special Character SED/AWK removal

I have a script that produces an output containing '/.ssh'. I am trying to find a way of parsing only this data from a single line, without removing any other special characters contained within the output as a result of the parse. Any help would be appreciated (6 Replies)
Discussion started by: Raggedranger333
6 Replies

10. Shell Programming and Scripting

awk syntax doubt - trailing 1 value

In the below awk syntax, what does the value '1' signify? awk '{....}1' file some eg: awk '{gsub(/]/,"")}1' awk 'BEGIN{ORS=""}1' awk '{ORS=(!(NR%5)?"":"\n")}1' (4 Replies)
Discussion started by: royalibrahim
4 Replies
Login or Register to Ask a Question