help, extract username from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help, extract username from file
# 1  
Old 12-29-2011
help, extract username from file

there is a text file like this

text here
text here
text here
text here

USER=someusername here

text here
text here
text here




how can i extract the someusername from this file which has a path like /home/myfile.txt?

i want to store it in a variable $u



thanks in advance!
# 2  
Old 12-29-2011
Code:
$ u=`grep "^USER" /home/myfile.txt | cut -d= -f2`
$ echo $u
someusername

# 3  
Old 12-29-2011
it works, thank you!
# 4  
Old 12-29-2011
Code:
 
awk -F"[ =]" '/^USER/ {print $2}' /home/myfile.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Why does "ps -[u|U] username" not list processes when username is numeric?

Greetings, The title pretty much says it all. I've snooped everywhere and can't find anything on this. Since our organization went to numeric usernames, using the u|U option for ps returns no processes. Example passwd entry: 320074:DjZAJKXun8HBs:10129:6006:Joe Y:/cadhome/analysis/jy:/bin/bash... (4 Replies)
Discussion started by: crimso
4 Replies

2. UNIX for Dummies Questions & Answers

Mailx: extract username from a file

Hey guys, I am trying to send email to the usernames listed in a ascii file. I know about the .mailrc file. I want to know if I there is a way to extract the usernames from a file and email them. I tried something like this: mailx -s "subject" '~cat... (2 Replies)
Discussion started by: Nirav4
2 Replies

3. Shell Programming and Scripting

Help with calling to file for a username and password combo

Hokay...first post, and I have been doing Linux scripting for a total of 2 days now. I think I am doing pretty well, but awk and arrays(what I think I need here) is a bit above me so far. I have written a script that will take and either create or modify 5 users, and passwords. It checks... (6 Replies)
Discussion started by: cashman04
6 Replies

4. Shell Programming and Scripting

[Solved] Get username, etc. from config file

how can i get the database name from a config file its like this: // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'userabc_wrdp1'); (there might be spaces in the front of "define") i want to store... (0 Replies)
Discussion started by: vanessafan99
0 Replies

5. Shell Programming and Scripting

Get username of last user to modify a file

Possible to get this? Thanks (2 Replies)
Discussion started by: stevensw
2 Replies

6. Shell Programming and Scripting

How to Determine the file owner's username

I've read the following post here and I get no output from the command. I've tried changing the '$3' to $5, 7, 10...and still nothing. Ultimately what I'd like to is determine who owns the file and rename it to file_name_$USERNAME. $ uname -a SunOS sun001 5.10 Generic_118833-33 sun4u sparc... (3 Replies)
Discussion started by: nadeemsm
3 Replies

7. Shell Programming and Scripting

To find the username in /etc/passwd file

Hi, I need to a shell script to list out only the username in the /etc/passwd file. Regards Siva (7 Replies)
Discussion started by: gsiva
7 Replies

8. Shell Programming and Scripting

Need to modify a file of different username through script.

Hi ! All I want to write a script where, it will open a new shell with a username / pwd and modify a file of same username and exit. example: 1. UserA 2. UserB- FileB ScriptA -> su UserB -> Modify FileB -> Exit ScriptA Can somebody give me a direction , on how to... (2 Replies)
Discussion started by: dashok.83
2 Replies

9. UNIX for Dummies Questions & Answers

How to get the Username stored in another file

Hello, I have a file FSGReport.info which reads as export username=abc export password= 1333 Now I have another FTP script file FTP.sh in which I need to access the username and password stored in the file FSGReport.info . How can I access this file and get the username and password. Please... (1 Reply)
Discussion started by: vnatarajan
1 Replies

10. AIX

How transfer sql file from one serverto another without username and password

hi there, Please help me How transfer sql file from one server to another without username and password .i know just IP address. Thanks Arpit (1 Reply)
Discussion started by: Arpitmitm
1 Replies
Login or Register to Ask a Question