cat in linux, file holding special charcters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cat in linux, file holding special charcters
# 1  
Old 09-11-2008
cat in linux, file holding special charcters

Hi
I'd like to cat, in linux, a file that holds special charcters, like "-->" and ">" and "]"
For example I have a file named test123.txt
it looks like this:
2008-09-11 00:27:01,496 -
< 0 > --> Start calculation of pattern [PROCESS_complex3], Pattern was split to [1] pattern graphs
< 0 > System Tqls Optimizer going to ask System Tqls results for all graph's elements except [-13]
< 16 > System Tqls Optimizer got System tqls results for [-11]
< 16 > Entered OverallPatternGraphCalculator witks [2] ; -15(-11 --> -13) - container_f ; -19(-11 --> -17) - container_f] calculation size [0 consistent=true]
< 16 > Entered ComponentGraphCalculator with component [Num of nodes [3] ; -17 - process ; -13 - disk ; -11 - host Num of links [2] ; -15(-11 --> -13) - container_f ; -19(-11 --> -17) - container_f, elements size 0] calculation size [0 consistent=true]
< 16 > Entered CompositeCalcul [2] ; -15(-11 --> -13) - container_f ; -19(-11 --> -17) - container_f, elements size 0] calculation size [0 consistent=true]
< 7500 > Calculation ended, result size [1769 consistent=false]
< 7500 > Calculation ended, result size [1769 consistent=false]
< 7500 > Entered ConsistencyChe- process ; -13 - disk ; -11 - host Num of links [2] ; -15(-11 --> -13) - container_f ; -19(-11 --> -17) - container_f] calculation size [1769 consistent=false]
< 7500 > Consistency at pattern level was found to be required due to previous calculation inconsistency
< 7516 > Calculation ended, result size [1769 consistent=false]
< 7516 > Calculation ended, result size [1769 consistent=false]
< 7516 > Result size [1769]
I want to cat it, the result should be:
< 0 > --> Start calculation of pattern [PROCESS_complex3], Pattern was split to [1] pattern graphs
< 7516 > Result size [1769]
I tried varations of the following command:
cat test123.txt | grep "> --> Start calculation of pattern [" | grep "> Result size ["
I tried it with one '
and with \ before the special chars etc...
Any Ideas ?
Thanks Smilie
# 2  
Old 09-11-2008
Code:
grep -e 'Start calculation of pattern' -e 'Result size' file.txt

You do not need cat, grep -e can search for multiple patterns, and you can sometimes find unique pattern identifiers that do not use metacharacters.
# 3  
Old 09-11-2008
Thanks jim :-)

I need to know how can I include special chars like: < > [ ] -- etc..
cause I need to look fo the exact line "> --> Start calculation of pattern "
the line "Start calculation of pattern" can appear in other places
# 4  
Old 09-11-2008
Hope this helps:

grep -E '(<.*Start calculation|<.*Result size)' file.txt
# 5  
Old 09-11-2008
Other sepcial characters are escaped with a backslash \ this prevents grep or sed from turning the character into a metacharacter
# 6  
Old 09-14-2008
Thanks Jim :-)
It's working
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Linux

File conversion and removing special characters from a file in Linux

I have a .CSV file when I check for the special characters in the file using the command cat -vet filename.csv, i get very lengthy lines with "^@", "^I^@" and "^@^M" characters in between each alphabet in all of the records. Using the code below file filename.csv I get the output as I have a... (2 Replies)
Discussion started by: dhruuv369
2 Replies

2. Homework & Coursework Questions

Meta charcters

find out lines in a given file consisting of the following pattern BCAA, BCAAA, BCAAAA, BCAAAAA, BCAAAAAA (1 Reply)
Discussion started by: Phaneendra G
1 Replies

3. UNIX for Dummies Questions & Answers

Meta charcters

Find out lines in a given file consisting of the following pattern BCAA, BCAAA, BCAAAA, BCAAAAA, BCAAAAAA (0 Replies)
Discussion started by: Phaneendra G
0 Replies

4. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

5. UNIX for Advanced & Expert Users

Substitution when special charcters involved

I am trying to substitute a substring in a file and am having difficulty due to the presence of 'special characters' I tried sed -e "s/Bob's birthday 13/11/08 (today)/Bob's birthday 14/11/08 (tomorrow)/" file1 This does not action any change due to the square brackets. How can I cater... (5 Replies)
Discussion started by: SAMZ
5 Replies

6. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

7. UNIX for Advanced & Expert Users

Line Longer Than 2048 Charcters

I have a csv file with a record size of greater than 2048.So when i try to open the file in VI..This is the error i get (test.csv" A line cannot be longer than 2048 characters) Is there a way i can change this parameter to read a bigger line (2 Replies)
Discussion started by: kris01752
2 Replies

8. UNIX for Advanced & Expert Users

remove charcters

How do i remove single quotes(') from a file. Can we use sed for it (2 Replies)
Discussion started by: kris01752
2 Replies

9. Solaris

Handling Special Charcters

Dear All, I have created a UTF-8 database to store multi-lingual charcters. Below is the query from which i insert from Winsql (front-end third party database browser tool), the data gets inserted properly. insert into a (no, lbl) values (1, "Cliquez ici pour revenir Ã_ la recherche de... (2 Replies)
Discussion started by: lloydnwo
2 Replies
Login or Register to Ask a Question