The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 03:59 AM
Grep pankajkrmishra Shell Programming and Scripting 15 09-01-2006 03:00 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-25-2006 01:20 AM
grep pls help.. esham Shell Programming and Scripting 19 03-17-2005 06:44 AM
Grep/Sed help? CKS Shell Programming and Scripting 3 03-19-2004 06:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-03-2006
harish_oty harish_oty is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 4
grep with LPAD or RPAD

Hi,
Are there any options for using options like RPAD(),LPAD() functions in SQL?If yes, How can I use grep command with thease options?

Any help would be appreciated.
Thanks in Advance.
-Harish
  #2 (permalink)  
Old 10-03-2006
srikanthus2002's Avatar
srikanthus2002 srikanthus2002 is offline
Registered User
  
 

Join Date: Sep 2006
Location: Can u guess...!
Posts: 160
Hi harish,

I don't know about those function (SQL). can you give more details.

Thanks
  #3 (permalink)  
Old 10-03-2006
harish_oty harish_oty is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 4
Hi Srikanth,
Consider below:-
test___1
test___2
test__10
test_110

Thease are the contents of a file where the number column is right aligned.
Please consider "___" symbol as blank spaces.
If I want to extract "test 110", I give grep "test $no" where no is a variable and consider now it is 110. This will extract "test 110". If I want to extract "test 10", If I give the same command grep "test $no", where no is 10, It won't extract because of it has got 2 blank spaces between test and 10. So I need to have a option like LPAD in other languages, E.g. LPAD("10",3," ") will return 1 blank space followed by 10. So I can assign this value to a variable and now the value can be no=" 10". Now I can go with grep, It will work.

I hope you understood this.
Any suggestion on this?
TIA
-Harish

Last edited by harish_oty; 10-03-2006 at 06:27 AM..
  #4 (permalink)  
Old 10-03-2006
srikanthus2002's Avatar
srikanthus2002 srikanthus2002 is offline
Registered User
  
 

Join Date: Sep 2006
Location: Can u guess...!
Posts: 160
I think , It would be helpful for you


Code:
FILE=input_filename
no=10
        cat $FILE | awk '$2 ~ /'"$no"'/ {print $1 " " $2}'

if any problem ..pls don't hesitate to ask help..


Thanks
Srikanth
  #5 (permalink)  
Old 10-03-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
try this


Code:
no=1
grep "test *$no$" file

or


Code:
no=1
sed -n "/test *$no$/p" file

  #6 (permalink)  
Old 10-03-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
Another way using grep :

Code:
grep "test[[:space:]]*$no" file

Jean-Pierre.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0