grep ^ as a character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep ^ as a character
# 1  
Old 02-09-2011
grep ^ as a character

I have a pwd file with a number of errors like: ^[ and [[^[
when I
Code:
grep ^

I get the whole file since it thinks it's new line. Should I \ to escape this?
# 2  
Old 02-09-2011
Yes, you should escape it.

Code:
grep \\^ file
# or
grep "\^" file

otherwise
Code:
fgrep ^ file

# 3  
Old 02-09-2011
TY, but this is strange. If I vi the file I see the ^ in the user record. If I grep it I don't see the ^.
That was why my grep \^ was falling thru.
# 4  
Old 02-09-2011
What do you mean by "errors"? Are these ^[, etc. escape characters?

Can you cat -v file and post part of the output which contains these characters?
This User Gave Thanks to Scott For This Post:
# 5  
Old 02-09-2011
when I cat -v file
I can see the ^ symbol
Code:
bxxxxb:*:xxxx0:Bxxxan W. Bxxxxx^?rf:/usr/ids/bxxxxb:/usr/bin/ksh
exxxxxc:*:xxxxx:Cxxx Exxxxxo^[[C [xxxSR x0]:/usr/ids/exxxxxxc:/usr/bin/ksh
jxxxxxl:*:xxxxxxxxx:^xxxxxle Jxxxxon [AxxxxP x0]:/usr/ids/jxxxxxl:/usr/bin/ksh

errors:
Line 1: ^?
Line 2: ^[
Line 3: ^

So, the ^ symbol is the one constant that I can use to find lines with errors in them.

---------- Post updated at 11:39 AM ---------- Previous update was at 11:14 AM ----------

This worked
Code:
cat -v infile | grep "\^" > tmp2.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grep only some part of character?

Hi, I have log : # cat log $ cat 4 2014092014 2014102014 2014112023 2014123014 2014010100 2014010101 2014010102 2014010103 2014010104 2014020123 2014020115 2014020116 (3 Replies)
Discussion started by: justbow
3 Replies

2. Shell Programming and Scripting

Grep -F for special character

a='CASH$$A' /usr/xpg4/bin/grep -F "$a" *.txt It is not able to grep CASH$$A string as it contains special character $$. I also tried with /usr/xpg4/bin/grep -F '$a' *.txt but still not working. I have to assign CASH$$A to a variable and serach that variable..i dont want to search the... (8 Replies)
Discussion started by: millan
8 Replies

3. UNIX for Dummies Questions & Answers

Grep character æ

Hello, Im trying check if character "æ" (alt+145) is included or not in some files. To do that I have written a scrip with vi that basically is a loop of all these compressed files and something like: zcat $file | grep æ >> logtocheck.out ; The problem is that æ is translated to something like... (3 Replies)
Discussion started by: ngb
3 Replies

4. UNIX for Dummies Questions & Answers

How to grep until a certain character?

Hi, so I have a file containing many repetitions of the pattern block displayed below: >NM_13489075 ACGUGCUAGCUUAGCGA AGCUAGCUGAUCGAUGC ACGUAGCUAGCUGAUCG GAUCGA >NM_13489023 ACGUGCUAGCUUAGCGA AGCUAGCUGAUCGAUGC ACGUAGCUAGCUGAUCG GAAGUC I was wondering how to grep, for example, a... (5 Replies)
Discussion started by: ShiGua
5 Replies

5. UNIX for Dummies Questions & Answers

Grep to return lines not containing a character

Hello , this is my first topic cause I need your little help:( I got .txt file, and I want to find lines without letter 'a', so im writing: grep "" list.txt (list.txt is the file of course) and i have no idea why it's not working because it shows lines with a. (1 Reply)
Discussion started by: bbqtoss
1 Replies

6. UNIX for Advanced & Expert Users

Grep character classes '\w' '\d'

I am learning regex fundamentals on my own and when I try to use \w for characters (i.e. ), or \d for digits () it doesnt work even though I see in greps man page that \w should be the same as ]... ] and those types of syntactic character classes do work for me, its just the shorthand \w \W and... (4 Replies)
Discussion started by: glev2005
4 Replies

7. UNIX for Advanced & Expert Users

grep in special character

All, I am trying to grep "-----" from a test when i use this i am getting the below error. What is the reason for this ?????... How can i over come this ##) echo "----------------- test_sys_job -----------------" | grep "-----------------" grep: illegal option -- - grep: illegal... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

8. UNIX for Dummies Questions & Answers

grep with wilcard character(*)

Hello people, I am trying to grep out a certain pattern from some files. The situation is like this: constantstring1<random data>constantstring2 I am using the following command (which clearly is not working!!!): datestring=<some date in YYYYMMDD format> searchstring=$datestring"*_xyz" grep... (2 Replies)
Discussion started by: Rajat
2 Replies

9. UNIX for Dummies Questions & Answers

Grep for X character on a word

How can I grep for a certain letter that only shows on the 3rd letter or character. ex: ASGHDY SHTYRD SDTYRD IGIKGD I only want the TY part of the 3rd character so output would only be SHTYRD and DDTYRD - I only want the TY on the 3rd character. THANKS (5 Replies)
Discussion started by: jjoves
5 Replies

10. UNIX for Dummies Questions & Answers

GREP a string with NULL Character

Does anyone know how to use grep/egrep to find a string that contains a null character? i.e.: the string looks like this: null0001nullN well I want to be able to : grep '0001N' is there a wildcard character or something that I can put in the grep to include the nulls? (3 Replies)
Discussion started by: weerich
3 Replies
Login or Register to Ask a Question