How to compare particular string, if it is equal put into a new file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to compare particular string, if it is equal put into a new file
# 1  
Old 06-18-2010
Bug How to compare particular string, if it is equal put into a new file

Hi,
I have a file (sample.txt) this file contains below text.
Code:
./au
./11.5.0
./11.5.0/admin
./11.5.0/admin/driver
./po
./11.5.0
./11.5.0/admin
./11.5.0/admin/driver
./xxsbx/11.5.0/java/src
./xxsbx/11.5.0/lib
./xxsel
./xxsel/11.5.0
./xxsel/11.5.0/admin
./zfa
./zfa/11.5.0
./zfa/11.5.0/admin
./xxplb/11.5.0/workflow
./xxplb/11.5.0/workflow/bes
./[DEST_ENV=ERP11i_QTC_PRD.APP=XXAPPS.SERVER_BASE_PATH]
./[DEST_ENV=ERP11i_QTC_PRD.APP=XXAPPS.SERVER_BASE_PATH]/admin


here my requirement is in each line after 2 charcters (./)
if next 2 characters (means 3,4) is "xx" then i want to print that complete line into another file.
Thanks in Advance.

Regards
Gagan.

Last edited by Franklin52; 06-18-2010 at 09:07 AM.. Reason: Please use code tags!
# 2  
Old 06-18-2010
Like this?
Code:
$> grep ^..xx.* infile > newfile
$> cat newfile
./xxsbx/11.5.0/java/src
./xxsbx/11.5.0/lib
./xxsel
./xxsel/11.5.0
./xxsel/11.5.0/admin
./xxplb/11.5.0/workflow
./xxplb/11.5.0/workflow/bes

# 3  
Old 06-24-2010
Thanks a lot Zaxxon
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare first column from two csv files with greater than or equal, and less than

I have two csv files of different sizes. The output file needs to have file1 contents on top of file2 contents where file2 col1 is >= to file1 col1, and file2 col1(same value) is < file1 col1 (next value). So basically, some file2 rows will be matched to the same file1 row because it is the closet... (7 Replies)
Discussion started by: aachave1
7 Replies

2. Shell Programming and Scripting

Bash not equal string comparison

Why does this cause an infinite loop? #!/bin/bash while ]; do echo "$(ipcs | awk '{print $2}')" done echo exit 0 I have verified I eventually get Semaphore so it should break out of the while loop. $ echo $(ipcs | awk '{print $2}') Shared shmid 262145 294914... (6 Replies)
Discussion started by: cokedude
6 Replies

3. Shell Programming and Scripting

Put a string to the beginning of a file without a linefeed

Hello, I need to put the following string to the beginning of a file - but it should not create a newline at the end of the string. So, the file I have is a compressed one - with gzip. And I would like to add an ASCII-String to the beginning of the file. The string has a length of 69... (5 Replies)
Discussion started by: API
5 Replies

4. Shell Programming and Scripting

Compare two CSV files and put the difference in third file with line no,field no and diff value.

I am having two csv files i need to compare these files and the output file should have the information of the differences at the field level. For Example, File 1: A,B,C,D,E,F 1,2,3,4,5,6 File 2: A,C,B,D,E,F 1,2,4,5,5,6 out put file: (12 Replies)
Discussion started by: karingulanagara
12 Replies

5. Shell Programming and Scripting

AWK splitting a string of equal parts of 500 chars

Hi , can someone help me how to make an AWK code for splitting a string of equal parts of 500 chars in while loop? Thank you! (4 Replies)
Discussion started by: sanantonio7777
4 Replies

6. Shell Programming and Scripting

Take values from a column and put it in a variable and compare

Hi, I have a table in unix from which i want to read the contents line by line, then filter out the values from 6th column one by one and compare it a fixed value. How to do this? (7 Replies)
Discussion started by: arijitsaha
7 Replies

7. Shell Programming and Scripting

Use grep sed or awk to extract string from log file and put into CSV

I'd like to copy strings from a log file and put them into a CSV. The strings could be on different line numbers, depending on size of log. Example Log File: File = foo.bat Date = 11/11/11 User = Foo Bar Size = 1024 ... CSV should look like: "foo.bat","11/11/11","Foo Bar","1024" (7 Replies)
Discussion started by: chipperuga
7 Replies

8. Shell Programming and Scripting

compare columns for equal values and output a summary

Hi all I am trying to scan a file that has 3 columns: red blue 123351 red blue 848655 red blue 126354 red blue 023158 black white 654896 red blue 650884 I want an output that sums the rows that have matching columns 1 and 2 :wall: red blue has 5 entries black white has 1 entry ... (4 Replies)
Discussion started by: reno
4 Replies

9. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

10. Shell Programming and Scripting

How to compare file name with a string

Hi, Suppose in some directory (/APPS/TEST) I have a file ABCTEST.csv. I want to write a IF condition in which I want to check if filename contains the string ABC then I will do certain operations . I have a variable having value as /APPS/TEST/ABCTEST.csv How Can I achieve this...please... (14 Replies)
Discussion started by: vishalaksha
14 Replies
Login or Register to Ask a Question