Sponsored Content
Top Forums Shell Programming and Scripting search between keywords and make a single line Post 302723841 by durden_tyler on Tuesday 30th of October 2012 10:56:30 PM
Old 10-30-2012
Code:
$
$
$ cat f14
abcd today
is
great
day;
abcd
another one
over
here;
some
text
here;
and some more...
$
$
$
$ perl -ne 'chomp;
            if (/abcd/)         {$x .= $_; $in = 1}
            elsif (/;/ and $in) {print "$x $_\n"; $in = 0; $x = ""}
            elsif ($in)         {$x .= " $_"}
            else                {print $_,"\n"}
           ' f14
abcd today is great day;
abcd another one over here;
some
text
here;
and some more...
$
$
$ perl -0ne 'while (/^(abcd.*?;|.*)$/msg) {$x=$1; $x =~ s/\n/ /g if $x =~ m/abcd/; print "$x\n"}' f14
abcd today is great day;
abcd another one over here;
some
text
here;
and some more...

$
$
$

tyler_durden

Last edited by durden_tyler; 10-31-2012 at 12:09 AM..
This User Gave Thanks to durden_tyler For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and replace words between two keywords

Hi, I have a file which contains the following : select * from test where test_id=1; select id from test1, test2 where test_id=1 and test_id=2; select * from test1, test2, test3 where test_id=4 and test2_id where in (select test2_id from test2); select id1, id2 from test ... (6 Replies)
Discussion started by: vrrajeeb
6 Replies

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

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

How to search for keywords in subsequent lines

Hi all, I am looking for a coomand to search for the keywords in susequenct lines. Keyword1 in a line and Keyword2 in the very next line. Once i found the combination ineed to print the lines with patterns and the line above and one below. I am giving an example here: Keywords are :ERROR and... (12 Replies)
Discussion started by: rdhanek
12 Replies

5. Shell Programming and Scripting

Search a file with keywords

Hi All I have a file of format asdf asf first sec endi asdk rt 123 ferf dfg ijglkp (7 Replies)
Discussion started by: mailabdulbari
7 Replies

6. Shell Programming and Scripting

Try to make a single line to syslog.

Hi again: Following the thread: https://www.unix.com/shell-programming-scripting/147755-format-lines-file.html I couldn't solve my problem, so I ask you again gurus: I have this code: nohup /usr/sbin/auditstream | /usr/sbin/auditselect -m -e "event== S_ENVIRON_WRITE || event==... (2 Replies)
Discussion started by: iga3725
2 Replies

7. UNIX for Dummies Questions & Answers

search all file for particular text and make changes to line 3

Hi All, I am sitting on HPUX. I want to change the exit into #exit, which appears into 3red line of code in shell scripting, wondering how shell script to be called up to perform action. I have following code in all files. Now, I need to find the text exit and replace into #exit. #!/sbin/sh... (10 Replies)
Discussion started by: alok.behria
10 Replies

8. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

9. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies
SSGREP(1)							       GNOME								 SSGREP(1)

NAME
ssgrep - search spreadsheets for strings SYNOPSIS
ssgrep [OPTIONS] [FILES] DESCRIPTION
This manual page briefly documents the ssgrep command. ssgrep is a command line utility to search for strings in spreadsheets of any format supported by gnumeric. OPTIONS
This program follows the usual GNU command line syntax, with single letter options starting with a single dash (`-') and longer options starting with two dashes (`--'). Options controlling input file handling --recalc Recalculate all cells Options controlling patterns and pattern matching -f, --keyword-file=FILE The path to a text file containing one key per line -i, --ignore-case Ignore differences in letter case -w, --word-regexp Match only whole words -F, --fixed-strings Pattern is a set of fixed strings -R, --search-results Search results of expressions too -v, --invert-match Search for cells that do not match Options controlling output in general -c, --count Only print a count of matches per file -L, --files-without-matches Print filenames without matches -l, --files-with-matches Print filenames with matches -q, --quiet Suppress all normal output -H, --with-filename Print the filename for each match -h, --without-filename Do not print the filename for each match -n, --print-locus Print the location of each match -T, --print-type Print the location type of each match Help options -V, --version Display ssgrep's version -?, --help Display the supported options --usage Display a brief usage message EXAMPLE
To search for the string "SUM" in the file foo.gnumeric : ssgrep SUM foo.gnumeric To search for the strings from the file keywords in the spreadsheet foo.xls : ssgrep --keyword-file=keywords foo.xls LICENSE
ssgrep is licensed under the terms of the General Public License (GPL), version 2. For information on this license look at the source code that came with the software or see the GNU project page <http://www.gnu.org>. COPYRIGHT
The copyright on ssgrep and the gnumeric software and source code is held by the individual authors as is documented in the source code. AUTHOR
ssgrep's primary author is Jody Goldberg <jody@gnome.org>; ssgrep builds on the gnumeric codebase. The initial version of this manpage was based on ssindex.1 by J.H.M. Dassen (Ray) <jdassen@debian.org>. SEE ALSO
beagled(1), gnumeric(1), ssconvert(1), ssindex(1) The Gnumeric Homepage <http://www.gnome.org/projects/gnumeric/>. The GNOME project page <http://www.gnome.org/>. gnumeric 2009-02-08 SSGREP(1)
All times are GMT -4. The time now is 02:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy