Using awk to print line starting with particular word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using awk to print line starting with particular word
# 1  
Old 08-26-2010
Using awk to print line starting with particular word

Hi Geeks,

Consider this line:

driver=c:\folder1\folder2

The above line is contained in a variable say 'var' . I want to copy everything after 'driver=' in to another variable say var2.

Please tell me how can this be done.
# 2  
Old 08-26-2010
Code:
$> var="driver=c:\folder1\folder2"
$> var2=${var#*=}
$> echo $var2
c:\folder1\folder2

This User Gave Thanks to zaxxon For This Post:
# 3  
Old 08-26-2010
Ha!

It's an awk question Smilie

Code:
$> var2=$(echo $var | awk -F= '{print $2}')


Last edited by Scott; 08-26-2010 at 10:50 AM.. Reason: Changed my PS1 :)
This User Gave Thanks to Scott For This Post:
# 4  
Old 08-26-2010
Pfff! SmilieSmilie
It's var2=... not $var2=...
# 5  
Old 08-26-2010
Thanks Guys
# 6  
Old 08-30-2010
Finally something not best done in awk! Smilie

The parameter substitution is much more slick.

Mike
# 7  
Old 08-31-2010
What you all are saying will return line after ("=")

But the line should be returned after ("driver=").
Any thoughts???
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get first word only starting of a line

Hi, I am trying to get longest line in a .gz file without extract the file. I am using the below command to get the longest line. zcat /a/b/c/file.gz |awk '{print length, $0}'|sort -nr|head -1 247 AAAAAAAAAAAAAAAAAAAAAAAAA BBBBBBBBBBBBBBBBBBBAAAAAA CCCCCCCCCCC DDDDDDDDDDDD EEEEEEEEEEEEEE... (4 Replies)
Discussion started by: k_manimuthu
4 Replies

2. Shell Programming and Scripting

How to print line starting with certain string together with its following line?

Dear all, How can I print line starting with certain string together with its following line. Example is as follows: Input file: @M01596:22:000000000-A7YH7:1:1101:16615:1070 2:N:0:1... (2 Replies)
Discussion started by: huiyee1
2 Replies

3. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

4. Solaris

awk - Print variable number of colums from a starting column

Hi guys, I usualy am able to google awk stuff but I can't find it so far and there are so many awking gurus here that I will give it a shot. I want to print $1;$3;"$5 up to the $NF". In other words, I can have 1000 colums, but need to have $5 up to the end. I started with the idea of... (2 Replies)
Discussion started by: plmachiavel
2 Replies

5. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

6. Shell Programming and Scripting

How to print last word of line

Hi, How to print last word of line? #!/bin/bash x1="This is Kiran" echo "$x1" how to print "Kiran" in new variable.i.e x2=kiran (7 Replies)
Discussion started by: kiran_j
7 Replies

7. Shell Programming and Scripting

How to remove all words starting from a matching word in a line

Hi Guys, I have a file like this: wwwe 1 ioie ewew yyy uuu 88 erehrlk 4 ihoiwhe lkjhassad lkhsad yyy mmm 45 jhash lhasdhs lkhsdkjsn ouiyrshroi oihoihswodnw oiyhewe yyy ggg 77 I want to remove everything after "yyy" and including "yyy" from each line in the file. So I want:... (2 Replies)
Discussion started by: npatwardhan
2 Replies

8. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies

9. Shell Programming and Scripting

Print starting 3rd line until end of the file.

Hi, I want to Print starting 3rd line until end of the file. Pls let me know the command. Thanks in advance. (1 Reply)
Discussion started by: smc3
1 Replies

10. Shell Programming and Scripting

print next line if matches a particular word..need help

Hi i need a help for making a script whch can print next line if it matches a particular word like file1 have ename Mohan eid 2008 ename Shyam eid 345 if scipt got Mohan it will print next line (eid 2008) pls help me .......:) (2 Replies)
Discussion started by: anish19
2 Replies
Login or Register to Ask a Question