![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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. |
|
||||
|
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 \\ |
|
||||
|
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? |
|
||||
|
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 =" |
|
||||
|
Cheers for the help guys, that's that sorted now.
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|