one liner needed


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users one liner needed
# 1  
Old 12-22-2009
one liner needed

Hi

I have a file say (a.txt) which has following

a.txt
----

$$var1=Tom
$$var2=Kim

I need a one liner which searches the file(a.txt) for $$var1 and returns the value in it(Tom).

Thanks in advance
Ammu
# 2  
Old 12-22-2009
Code:
AWK -F = '/\$\$var1/ {print $2}' /tmp/a.txt

Substitute AWK with nawk or gawk or awk depending on the OS used.
# 3  
Old 12-22-2009
sed:
Code:
sed -n 's/\$\$var1=//p' a.txt

# 4  
Old 12-22-2009
Quote:
Originally Posted by ammu
Hi

I have a file say (a.txt) which has following

a.txt
----

$$var1=Tom
$$var2=Kim

I need a one liner which searches the file(a.txt) for $$var1 and returns the value in it(Tom).

Thanks in advance
Ammu
Code:
perl -wln -e 'print $1 if /^.*\=(.+)$/' a.txt

# 5  
Old 12-22-2009
Thanks for quick reply.
It is failing with below error

awk: syntax error near line 1
awk: bailing out near line 1
# 6  
Old 12-22-2009
Strange:
Code:
$ awk -F= '/\$\$var1/{print $2}' a.txt
Tom

# 7  
Old 12-23-2009
Hello ,
Code:
gaurav@localhost:~$ cat > a.txt
var1=tom
var2=kim
gaurav@localhost:~$ perl -wl -e 'open(FILE,"<a.txt");my $var=<STDIN>;chomp $var;while(<FILE>){print $1 if /^$var=(.+)/}'
var1
tom

This will take the name as input like var1 and give "tom"
Hope this is what you exactly want.
Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell one liner help

Hello, I am trying to sort/get some specific output from a ls command but however I am having no luck. The command I am using is 'ls -al /nim/dr/mksysb/\*'|grep -e _dr -e .tgz|cut -c37-90|cut -d" " -f2-8|cut -d_ -f1 the error is bash: ls -al /nim/dr/mksysb/\*: No such file or directory ... (1 Reply)
Discussion started by: hasn318
1 Replies

2. UNIX for Dummies Questions & Answers

sed one-liner

I have a data base of part numbers: AAA Thing1 BBB Thing2 CCC Thing3 File one is a list of part numbers: AAA234 BBB678 CCC2345 Is there a sed one-line that would compare a data base with and replace the part numbers so that the output looks like this? AAA234 Thing1 BBB678 Thing2... (5 Replies)
Discussion started by: jimmyf
5 Replies

3. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

4. Shell Programming and Scripting

help one liner...

Hi I have a log data that shows chunks of data like this: thisis example test, this is example test, this is example test thisis example test, this is example test, this is example test thisis example test, this is example test, this is example test thisis example test, this is example test,... (2 Replies)
Discussion started by: erick_tuk
2 Replies

5. Shell Programming and Scripting

Need a one liner

abc/abc1/abc2/abc3/abc4 i need a script to pick this above path when ever any patterns like the below will be found. abc/abc1 abc/abc1/abc2 abc1/abc2/abc3 abc2/abc3/abc4 abc2/abc3/ etc .... etc..... not only the above 5 but like these one.. any one liner will be of great... (1 Reply)
Discussion started by: debu182
1 Replies

6. Shell Programming and Scripting

Clarification needed for a SED one liner

I want to use SED to replace all new line characters of a file, I googled and found this one liner sed '{:q;N;s/\n//g;t q}' infile what do :q;N; and t q mean in this script? (6 Replies)
Discussion started by: kevintse
6 Replies

7. Shell Programming and Scripting

awk one liner

input a 100 200 300 b 400 10 output a 100 a 200 a 300 b 400 b 10 Thanx (6 Replies)
Discussion started by: repinementer
6 Replies

8. Shell Programming and Scripting

Help Needed with 1 liner AWK statement

Greetings, I attempting to create a line statement that will do the following: 1. Read the input file 2. Extract lines containing certain keep words 3. Print the lines in a tabular format (CSV) Help is what I have so far: # cat text.tx | egrep -i -e "(Check Name) | (Risk Level) |... (6 Replies)
Discussion started by: jroberson
6 Replies

9. Shell Programming and Scripting

1 liner question

This works: nslookup `uname -n`|tail -2|awk -F: '{print $2}' This does not aa=`nslookup `uname -n`|tail -2|awk -F: '{print $2}'` Why??? Solaris v10 Thanks Brandt (6 Replies)
Discussion started by: beppler
6 Replies

10. Shell Programming and Scripting

Perl One Liner

Hi , Can anybody explain how this perl one liner works.. It is to test whether the number is prime or not perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19 Thanks in advance Shihab (2 Replies)
Discussion started by: shihabvk
2 Replies
Login or Register to Ask a Question