Sponsored Content
Top Forums Shell Programming and Scripting Search pattern and write line into another file Post 302861987 by satyaatcgi on Thursday 10th of October 2013 03:24:23 AM
Old 10-10-2013
Search pattern and write line into another file

Hi,

I have a file which contains the below details.. My requirement is to fetch all the lines which are starting with "ABC_XY_" into 1 file and rest of the lines (not starting with "ABC_XY_") into another file.

Could you please help with what command needs to be used?
file1.txt
----------
Code:
ABC_XY_1234,John
ABC_XY_2345,Raj
ABC_XY_769536, Mark
ABC_XY_82758,George
ABC_XY_8643969,Kate
ABC_XY_93465, Nat
ABC_XY_3456846, Bush
ABC_XY_6907640,King
ABC_XY_5482582,Young
ABC_XY_567,George 
PQR_85493,Young
PQR_564,kate
PQR_422156,Mark
PQR_2565667, Joker
PQR_35235, Philips
PQR_3535, Glen
PQR_53535,Rossel
PQR_23438, Mark
PQR_436465, Tony

Expected o/p:
-------------------
Code:
out1.txt
-------
ABC_XY_1234,John
ABC_XY_2345,Raj
ABC_XY_769536, Mark
ABC_XY_82758,George
ABC_XY_8643969,Kate
ABC_XY_93465, Nat
ABC_XY_3456846, Bush
ABC_XY_6907640,King
ABC_XY_5482582,Young
ABC_XY_567,George 

Out2.txt
--------
PQR_85493,Young
PQR_564,kate
PQR_422156,Mark
PQR_2565667, Joker
PQR_35235, Philips
PQR_3535, Glen
PQR_53535,Rossel
PQR_23438, Mark
PQR_436465, Tony

SmilieCheers,
Satya

Last edited by Franklin52; 10-10-2013 at 04:37 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

modify a particular pattern starting from second line of the search pattern

Hi, I am new to this forum and i would like to get help in this issue. I have a file 1.txt as shown: apple banana orange apple grapes banana orange grapes orange .... Now i would like to search for pattern say apple or orange and then put a # at the beginning of the pattern... (2 Replies)
Discussion started by: imas
2 Replies

2. UNIX for Dummies Questions & Answers

modify a particular pattern starting from second line of the search pattern

Hi, I think you ppl did not get my question correctly, let me explain I have 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: ... (1 Reply)
Discussion started by: imas
1 Replies

3. Shell Programming and Scripting

Search a pattern in a file with contents in a single line

Hi all I am searching for a pattern in a file . The file content is in a single line.If am doing a grep or sed for the a particular pattern am getting whole file. I want the result in different lines. attaching the file for reference search pattern "/xxxxxx/hhhh/tttttttt/sss/" and... (4 Replies)
Discussion started by: sparks
4 Replies

4. Shell Programming and Scripting

search more than one pattern with perl on same line

Hi friends, I want to search for some hex error codes in some files. After the hex error code is found, the occurences would be counted. Afterwards the found hex errorcode would be cat into a separate file. Here is my code: #!/usr/bin/perl use File::Basename; my $find = $ARGV; my... (2 Replies)
Discussion started by: sdohn
2 Replies

5. Shell Programming and Scripting

Mutli line pattern search & replace in a xml file

Hello guys, I need your help for a specific sed command that would search for a multi line pattern and if found, would replace it by another multi line pattern. For instance, here is the input: <RefNickName>abcd</RefNickName> <NickName>efgh</NickName> <Customize> ... (0 Replies)
Discussion started by: xciteddd
0 Replies

6. Shell Programming and Scripting

How to search pattern and add that pattern in next line

Hi All, I am new to shell scripting and need help in scripting using CSH. Here is what I am trying to so, 1. Search a specific string e.g. "task" from "task (input1, out1)". 2. Extract the arguements "input1" and "out1" 3. Add them in separate lines below. eg. "int input1" , " integer out1" ... (7 Replies)
Discussion started by: deshiashish
7 Replies

7. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

8. Shell Programming and Scripting

How to use sed to search a particular pattern in a file backward after a pattern is matched.?

Hi, I have two files file1.txt and file2.txt. Please see the attachments. In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
Discussion started by: saurabh kumar
9 Replies

9. Shell Programming and Scripting

Search a pattern in a line and remove another pattern

Hi, I want to search a pattern in a text file and remove another pattern in that file. my text file look like this 0.000000 1.970000 F 303 - 1.970000 2.080000 VH VH + 2.080000 2.250000 VH VH + 2.250000 2.330000 VH L - 2.330000 2.360000 F H + 2.360000 2.410000 L VL - 2.410000 ... (6 Replies)
Discussion started by: sreejithalokkan
6 Replies

10. Shell Programming and Scripting

Search for a pattern in a file and split the line into two lines

Hi All, Greetings everyone !!! I have a file which has many lines, out of which one line is as below. I need to search for pattern "varchar(30) Select" and if exists, then split the line as below. I am trying to achieve this in ksh. Can anyone help me on this. (8 Replies)
Discussion started by: Pradhikshan
8 Replies
KATE(1) 							 KDE User's Manual							   KATE(1)

NAME
kate - Advanced text editor for KDE SYNOPSIS
kate [-s, --start name] [--startanon] [-n, --new] [-b, --block] [-p, --pid pid] [-e, --encoding name] [-l, --line line] [-c, --column column] [-i, --stdin] [-u, --use] [KDE Generic Options] [Qt Generic Options] DESCRIPTION
Kate is the KDE Advanced Text Editor. Kate also provides the editor part for various applications, under the name KWrite. Some of Kate's many features include configurable syntax highlighting for languages ranging from C and C++ to HTML to bash scripts, the ability to create and maintain projects, a multiple document interface (MDI), and a self-contained terminal emulator. But Kate is more than a programmer's editor. Its ability to open several files at once makes it ideal for editing UNIX(R)'s many configuration files. This document was written in Kate. OPTIONS
-s, --start name Start Kate with a given session. --startanon Start Kate with a new anonymous session, implies -n. -n, --new Force start of a new Kate instance (is ignored if start is used and another Kate instance already has the given session opened), forced if no parameters and no URLs are given at all. -b, --block If using an already running Kate instance, block until it exits, if URLs given to open. -p, --pid pid Only try to reuse kate instance with this pid (is ignored if start is used and another Kate instance already has the given session opened). -e, --encoding name Set encoding for the file to open You can use this to force a file opened in utf-8 format, for instance. (The command iconv -l provides a list of encodings, which may be helpful to you.) -l, --line line Navigate to this line -c, --column column Navigate to this column -i, --stdin Read the contents of stdin -u, --use Use an already running Kate instance; default, only for compatibility SEE ALSO
More detailed user documentation is available from help:/kate (either enter this URL into Konqueror, or run khelpcenter help:/kate). There is also further information available at the Kate website[1]. EXAMPLES
To open a file named source.cpp at column 15, line 25, in an existing Kate window, you could use: kate -c 15 -l 25 -u source.cpp If you have an active internet connection, you can take advantage of KDE's network transparency to open a file from an ftp site. If you do not have write permission on the remote server, the file will be opened read only and you will be prompted for a local filename to save to if you make changes. If you do have write permission, changes will be saved transparently over the network. kate ftp://ftp.kde.org/pub/kde/README AUTHORS
The maintainer of Kate is Christoph Cullmann<cullmann@kde.org>. A comprehensive list of authors and contributors is available in the complete user manual mentioned above. AUTHOR
Lauri Watts <lauri@kde.org> Author. NOTES
1. the Kate website http://kate-editor.org/ K Desktop Environment 2010-10-06 KATE(1)
All times are GMT -4. The time now is 04:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy