The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 find special characters?? sumitc AIX 3 05-04-2008 08:20 PM
unescaping special characters sriram_r Shell Programming and Scripting 3 02-06-2008 07:59 AM
Handling special characters using awk sam_78_nyc Shell Programming and Scripting 3 11-08-2007 05:55 PM
special characters nawnaw UNIX for Dummies Questions & Answers 2 05-18-2004 03:17 PM
awk/sed with special characters apalex Shell Programming and Scripting 5 05-06-2002 04:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-26-2007
Vashj Vashj is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
Grep with Special Characters

I need to sort a file, the sort is not a alphabetical sort, it's based on a predefined order which is read from a file called fSortOrder.

The format of the fSortOrder file is :
STARTPATH"
....
....

The file that needs to be sorted is called tmpUnsorted and contains data in the format :
<add key="STARTPATH" value="\\njros1a2226\LIFEPRO\V13\START" />
....
....

I read the fSortOrder file one line at a time and place this in a variable called lineMO. I use the line below to search the input for the variable :

isThere="$(grep $lineMO tmpUnsorted)"

This appears to work fine, but messes up the data, instead of placing
<add key="STARTPATH" value="\\njros1a2226\LIFEPRO\V13\START" /> in the variable.

<add key="STARTPATH" value="\njros1a2226\LIFEPRO\V13\START" /> is placed in the varialbe.

Is there anyway to fix this as the double \\ is vital and the file is useless without it.
  #2 (permalink)  
Old 11-26-2007
V3l0 V3l0 is offline
Registered User
  
 

Join Date: Nov 2007
Location: Belgium & France
Posts: 70
Try to replace
Code:
isThere="$(grep $lineMO tmpUnsorted)"
by
Code:
isThere="$(grep '$lineMO' tmpUnsorted)"
or
Code:
isThere=$(grep "$lineMO" tmpUnsorted)
  #3 (permalink)  
Old 11-26-2007
Vashj Vashj is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
Using "$lineMo" does not work (tried it)

Using '$lineMO' also does not work because the ' ' negates the meaing of $ and searches for the string $lineMO in the file rather than the contents of the variable $lineMO
  #4 (permalink)  
Old 11-26-2007
manzier manzier is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 9
grep with special characters

I beleive your code is already working. Try using:

isThere="$(grep $lineMO tmpUnsorted)"

and then check the varaible with:

print -r "$lineMO"

The -r will ignore special characters and you should see that the varaible does contain \\
  #5 (permalink)  
Old 11-26-2007
Vashj Vashj is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
print -r $lineMO works fine, but for some reason it's putting spaces in the variable before the first characrer

Instead of looking like this :
<add key="STARTPATH" value="\\njros1a2226\LIFEPRO\V13\START" />

It looks like this
<add key=".........STARTPATH" value="\\njros1a2226\LIFEPRO\V13\START" />
*The dots represent the blank spaces that appear.

How do you remove a leading tab from a variable?
  #6 (permalink)  
Old 11-26-2007
manzier manzier is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 9
The grep command is only going to return what it finds in tmpUnsorted so if there is not a tab in tmpUnsorted I would check your code to see where you have embeded it.

Removing a leading tab(specifally for your code):

TABLESS=$(print -r $isThere | sed 's/=" */="/') # Removes multiple whitspaces after ="

TAB=$(printf "\t")
TABLESS=$(print -r $isThere | sed "s/=\"$TAB/=\"/") # Removes single tab character after ="
  #7 (permalink)  
Old 11-27-2007
Vashj Vashj is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
Cheers for the help guys, that's that sorted now.
Sponsored Links
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 04:39 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