Sponsored Content
Top Forums Shell Programming and Scripting Search a pattern in a file with contents in a single line Post 302298219 by wempy on Tuesday 17th of March 2009 02:51:26 AM
Old 03-17-2009
if the whole file is one continuous line then grep will not help you, as it is line oriented (and so is sed). You could write a sed expression to only output the matched text using back references, but as your search expression contains only constants, what would be the point?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

make multiple line containing a pattern into single line

I have the following data file. zz=aa azxc-1234 aa=aa zz=bb azxc-1234 bb=bb zz=cc azxc-1234 cc=cc zz=dd azxc-2345 dd=dd zz=ee azxc-2345 ee=ee zz=ff azxc-3456 ff=ff zz=gg azxc-4567 gg=gg zz=hh azxc-4567 hh=hh zz=ii azxc-4567 ii=ii I want to make 2nd field pattern matching multiple lines... (13 Replies)
Discussion started by: VTAWKVT
13 Replies

2. Shell Programming and Scripting

awk pattern match and search in single statement

Hi All, I am trying to alter all lines between EXEC SQL and END-EXEC that have an INCLUDE in them. The following code search="INCLUDE " cp -f ${WORK}/$file.in ${WORK}/$file.wrk2 for item in `echo $search `; do > ${WORK}/$file.wrk1 awk -vITEM="$item" '{ if ( $0... (3 Replies)
Discussion started by: Bruble
3 Replies

3. Shell Programming and Scripting

Joining contents in multiple lines to a single line

I do have a file with contents splited into multiple lines ADSLHLJASHGLJSKAGHJJGAJSLGAHLSGHSAKBV AJHALHALHGLAGLHGBJVFBJVLFDHADAH GFJAGJAGAJFGAKGAKGFAK AJHFAGAKAGAGKAKAKGKAGFGJDGDJJDGJDJDFAG ... ... .... 100's of lines I would like to rearrange the content of this file so it will be a... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

4. Shell Programming and Scripting

Perl question - How do I print contents of an array on a single line?

I have the following code: print @testarray; which returns: 8 8 8 9 How do I return the array like this: The output is: 8, 8, 8, 9 (5 Replies)
Discussion started by: streetfighter2
5 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

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

7. Shell Programming and Scripting

Search Pattern and combine into single file

Hi Experts Please help me out with the following thing: 2 files and want the output file: {No for using FOR loop because I got 22 million lines} Tried that "It processes only 8000 records per hour" I need a faster way out !!! FileA: 9051 9052 9053 9054 9055 9056 9057 9058 9059 ... (5 Replies)
Discussion started by: navkanwal
5 Replies

8. Shell Programming and Scripting

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 ----------... (12 Replies)
Discussion started by: satyaatcgi
12 Replies

9. Shell Programming and Scripting

Search Pattern and Print lines in Single Column

Hi Experts I have small query where I request the into a single file Suppose: File1: {Unique entries} AA BB CC DD FileB: AA, 123 AA, 234 AA, 2345 CC, 123 CC, 5678 DD,123 BB, 7890 (5 Replies)
Discussion started by: navkanwal
5 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
GREP(1) 						      General Commands Manual							   GREP(1)

NAME
grep - search a file for a pattern SYNOPSIS
grep [ option ... ] pattern [ file ... ] DESCRIPTION
Grep searches the input files (standard input default) for lines (with newlines excluded) that match the pattern, a regular expression as defined in regexp(6). Normally, each line matching the pattern is `selected', and each selected line is copied to the standard output. The options are -c Print only a count of matching lines. -h Do not print file name tags (headers) with output lines. -i Ignore alphabetic case distinctions. The implementation folds into lower case all letters in the pattern and input before interpre- tation. Matched lines are printed in their original form. -l (ell) Print the names of files with selected lines; don't print the lines. -L Print the names of files with no selected lines; the converse of -l. -n Mark each printed line with its line number counted in its file. -s Produce no output, but return status. -v Reverse: print lines that do not match the pattern. Output lines are tagged by file name when there is more than one input file. (To force this tagging, include /dev/null as a file name argument.) Care should be taken when using the shell metacharacters $*[^|()= and newline in pattern; it is safest to enclose the entire expression in single quotes '...'. SOURCE
/sys/src/cmd/grep.c SEE ALSO
ed(1), awk(1), sed(1), sam(1), regexp(6) DIAGNOSTICS
Exit status is null if any lines are selected, or non-null when no lines are selected or an error occurs. GREP(1)
All times are GMT -4. The time now is 08:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy