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 05-07-2009, 03:44 AM   #1
niknak
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Rep: Reputation: 0
awk one liner help


Hi and hello to all.

I am working on a very small script as a complete newbie and need a little help on an awk expression.

What I need to do:

I have a txt file whose first and only line is:

--username:someusername --password:somepassword --server:someserver

I am trying to extract the actual password so I can use as part of a sed routine so am storing the output to a variable.

--password is always in the same position in the file, but not at the same char count.

I have an awk one line which just uses the man examples so I can easily get the output to a variable of --password:somepassword by using $2, but all i need is the text string 'somepassword' which is the actual password text.

So, can anyone help with a one liner that can extract the password from this file and store as a variable?

Thank you.
 
Old 05-07-2009, 04:52 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, welcome to LQ!

Code:
awk -F"[ :]" '{print $4}' file
should work. Untested, though, don't have awk here atm


Cheers,
Tink
 
  


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
IP Forward one-liner? JoeBleaux Linux - Networking 1 04-27-2009 10:24 AM
Help with Simple sed one liner SHARPY Linux - Newbie 10 04-12-2009 12:49 PM
Need one liner copy command madhi Linux - Software 2 07-31-2008 01:32 AM
Share your greatest one-liner!! PenguinPwrdBox General 3 08-20-2005 10:45 PM
one liner needed for search and replace chr15t0 Linux - General 2 09-24-2002 10:00 AM

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

All times are GMT -5. The time now is 02:08 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