How to use cat command in sed pattern searching


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to use cat command in sed pattern searching
# 1  
Old 08-22-2006
How to use cat command in sed pattern searching

Hi All,

I have a file named pattern.dat which contains pattern like
A1000090 250.00 250.00

i have one more file named test.dat in which this pattern is present.

What i should do is, in test.dat after this pattern i should append comments.

i used like this

sed "/`cat pattern.dat`/ a\
> COMMENT
> " test.dat

It is throwing error as
sed: command garbled: /A1000090 250.00 250.00 / COMMENT

please help me out to solve this probelm.

Thanks,
Sona.
# 2  
Old 08-22-2006
Dear Sona,

The error you are getting is probably because you are using "" on place of ''.
You can try this also.....it's little ugly but I think it might solve your purpose.....

sed '/[a-zA-Z0-9]* [0-9]*\.[0-9]* [0-9]*\.[0-9]*/ a\
COMMENT
' pattern.dat > test.dat

regards
Apoorva kumar
# 3  
Old 08-22-2006
Hi Apoorva,

I think u misunderstood my query...

I just want to search the pattern(present in pattern.dat) in test.dat and append a new line after that pattern in test.dat.

I tried with ur code..it is not working.

Thanks,
Sona.
# 4  
Old 08-22-2006
Ok ! Let me check it!!

regards
Apoorva kumar
# 5  
Old 08-22-2006
But the pattern should be taken from one file.It is not just any string we can use. so how can i do that?

how can i take the pattern from one file and check it in another file using sed since i need to append the comment text after that pattern.

Sona.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to replace two character pattern with another pattern

Not able to paste my content. Please see the attachment :-( (2 Replies)
Discussion started by: vivek d r
2 Replies

2. Shell Programming and Scripting

sed command to delete a pattern in a file

Hi Everyone, I have an unusual requirement. Here is where i am stuck for sometime now... I have this text file.. lets say .. output.sql... it has lot of entries... here below is part of the entry... .. . . . . . . . . . . . . . . . .... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

Searching and printing the only pattern using awk,sed or perl

Hi All, i have an output of command vmstat as below : $ vmstat System configuration: lcpu=4 mem=5376MB ent=1.00 kthr memory page faults cpu ----- ----------- ------------------------ ------------ ----------------------- r b avm fre re pi... (10 Replies)
Discussion started by: omkar.jadhav
10 Replies

4. Shell Programming and Scripting

Searching for a pattern and extracting records related to that pattern

Hi there, Looking forward to your advice for the below: I have a file which contains 2 paragraphs related to a particular pattern. I have to search for those paragraphs from a log file and then print a particular line from those paragraphs. Sample: I have one file with the fixed... (3 Replies)
Discussion started by: danish0909
3 Replies

5. Shell Programming and Scripting

sed command to print first instance of pattern in range

The following text is in testFile.txt: one 5 two 10 three 15 four 20 five 25 six 10 seven 35 eight 10 nine 45 ten 50 I'd like to use sed to print the first occurance of search pattern /10/ in a given range. This command is to be run against large log files, so to optimize efficiency,... (9 Replies)
Discussion started by: uschaafm
9 Replies

6. Shell Programming and Scripting

Place digit in front of the line searching pattern using sed command

hi All, i want to add the single digit front of the line in the report file and string compare with pattern file. patter file: pattern1.txt pattern num like 4 love 3 john 2 report file: report.txt i like very much but john is good boy i will love u so after execute... (9 Replies)
Discussion started by: krbala1985
9 Replies

7. Shell Programming and Scripting

Searching a pattern in file and deleting th ewhole line containing the pattern

Hi All, Please can someone assist in the script I have made that searches a pattern in a file and delete the whole line containing the pattern. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read value # check if the user has... (1 Reply)
Discussion started by: Shazin
1 Replies

8. Shell Programming and Scripting

Sed - Pattern Searching

Hi, Please take a look at the below eg. I would like to search for abc() pattern first and then search for (xyz) in the next line. If I can find the pattern, then I should delete the 3 lines. I can only find the pattern and delete but I am unable to find two patterns and delete. Any... (8 Replies)
Discussion started by: sreedevi
8 Replies

9. 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

10. Shell Programming and Scripting

Pattern searching pattern in c files

I have a problem in searching a specific pattern in c files. My requirement: I have to find all the division operator in all cfiles. The problem is, the multi line comments and single line comments will also have forward slash in it. Even after avoiding these comments also, if both... (6 Replies)
Discussion started by: murthybptl
6 Replies
Login or Register to Ask a Question