Sponsored Content
Top Forums Shell Programming and Scripting awk search for Quoted strings (') Post 302125960 by aigles on Monday 9th of July 2007 09:37:01 AM
Old 07-09-2007
Code:
awk -F "'" '{ for (f=1; f<=(NF-1)/2; f++) print $(f*2) }' input_text

Input text:
Code:
'This is a sample file for testing'
This does not have quotations
this also does not have quotations.
and this 'has quotations'.
first 'quotation 1' and second 'quotation 2', no more...
complete 'complete quotation' and 'incomplete

Output:
Code:
This is a sample file for testing
has quotations
quotation 1
quotation 2
complete quotation


Last edited by aigles; 07-09-2007 at 10:53 AM.. Reason: Add support for incomplete quoted string
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

odd behaviour with quoted input strings

I'm working with a java-based monitoring tool (Solaris/x86) which can be configured to call a shell script when a particular event occurs. The java app sends a set of quoted strings as input to the shell script. The problem I'm running into is that the shell script, when called by the java app,... (0 Replies)
Discussion started by: iron_horse
0 Replies

2. Shell Programming and Scripting

Varying number of awk search strings

I've created an awk script that handles a varying number of search strings handed to it as command line parameters ($1 $2 etc). There may be 1, or 2 or 3 or more. A simplified version of the script is: awk -v TYP="$1 $2 $3 $4 $5 $6" ' BEGIN { CTYP = split (TYP,TYPP," ") } ... (2 Replies)
Discussion started by: CarlosNC
2 Replies

3. Shell Programming and Scripting

Awk search for a element in the list of strings

Hi, how do I match a particular element in a list and replace it with blank? awk 'sub///' $FILE list="AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA,... (2 Replies)
Discussion started by: grossgermany
2 Replies

4. Shell Programming and Scripting

Using Awk to Search Two Strings on One Line

If i wanted to search for two strings that are on lines in the log, how do I do it? The following code searches for just one string that is one one line. awk '/^/ {split($2,s,",");a=$1 FS s} /failure agaf@fafa/ {b=a} END{print b}' urfile What if I wanted to search for "failure agaf@fafa"... (3 Replies)
Discussion started by: SkySmart
3 Replies

5. Shell Programming and Scripting

awk how to search strings within a file from two different lines

Hi, i would really appreciate any help anyone can give with the following info. Thanks in advance. I need to run a search on a file that contains thousands of trades, each trade is added into the file in blocks of 25 lines. i know the search has to take place between a time stamp specified... (4 Replies)
Discussion started by: sp3arsy
4 Replies

6. Shell Programming and Scripting

awk search strings from array in textfile

I am wanting to take a list of strings and loop through a list of textfiles to find matches. Preferably with awk and parsing the search strings into an array. // Search_strings.txt tag string dummy stuff things // List of files to search in textfile1.txt textfile2.txt The... (6 Replies)
Discussion started by: sdf
6 Replies

7. Shell Programming and Scripting

awk search an output string between two strings

I would like to search for strings stored in searchstringfile.txt in inputfiles. searchstringfile.txt J./F. Gls. Wal F. Towerinput1.txt What is needed is J./F. 12 var Gls. Wal 16 interp. Tower 12 input2.txt Awk shall search for F. 16 pt. J./F. 22 output.txt input1.txt J./F. = 12 var... (3 Replies)
Discussion started by: sdf
3 Replies

8. Shell Programming and Scripting

awk to search similar strings and add their values

Hi, I have a text file with the following content: monday,20 tuesday,10 wednesday,29 monday,10 friday,12 wednesday,14 monday,15 thursday,34 i want the following output: monday,45 tuesday,10 wednesday,43 friday,12 (3 Replies)
Discussion started by: prashu_g
3 Replies

9. Shell Programming and Scripting

awk strings search + print next column after match

Hi, I have a file filled with search strings which have a blank in between and look like this: S. g. Ehr. o. Jg. v. d. Chijs g. Ehr. Now i would like to search for the strings and it also shall return the next column after the match. awk -v FILE="search_strings.txt" 'BEGIN {... (10 Replies)
Discussion started by: sdf
10 Replies

10. Shell Programming and Scripting

awk? extract quoted "" strings from multiple lines.

I am trying to extract multiple strings from snmp-mib files like below. ----- $ cat IF-MIB.mib <snip> linkDown NOTIFICATION-TYPE OBJECTS { ifIndex, ifAdminStatus, ifOperStatus } STATUS current DESCRIPTION "A linkDown trap signifies that the SNMP entity, acting in... (5 Replies)
Discussion started by: genzo
5 Replies
CAMLP5(1)						      General Commands Manual							 CAMLP5(1)

NAME
camlp5 - Pre-Precessor-Pretty-Printer for ocaml mkcamlp5 - Create custom camlp5 mkcamlp5.opt - Create custom camlp5 (native code) ocpp5 - Universal preprocessor SYNOPSIS
camlp5 [ load-options ] [--] [ other-options ] camlp5o [ load-options ] [--] [ other-options ] camlp5r [ load-options ] [--] [ other-options ] camlp5sch [ load-options ] [--] [ other-options ] camlp5o.cma camlp5r.cma camlp5sch.cma mkcamlp5 mkcamlp5.opt ocpp5 [ load-options ] file camlp5o.opt [--] [ other-options ] camlp5r.opt [--] [ other-options ] DESCRIPTION
camlp5 is a Pre-Processor-Pretty-Printer for OCaml, parsing a source file and printing some result on standard output. camlp5o, camlp5r and camlp5sch are versions of camlp5 with some files already loaded (see further). camlp5o.cma, camlp5r.cma and camlp5sch.cma are files to be loaded in ocaml toplevel to use the camlp5 machinery mkcamlp5 and mkcamlp5.opt creates camlp5 executables with almost the same options than ocamlmktop. See further. ocpp5 is an universal preprocessor, treating any kind of source file, generating the same text with the possible quotations expanded. camlp5o.opt and camlp5r.opt are versions of camlp5o and camlp5r compiled by the native-code compiler ocamlopt. They are faster but not extensible. And they are not available in all installations of camlp5. LOAD OPTIONS
The load options select parsing and printing actions recorded in OCaml object files (ending with .cmo or .cma). Several usage of these options are authorized. They must precede the other options. An optional -- may end the load options. -I directory Add directory in the search path for files loaded. Unless the option -nolib is used, the camlp5 library directory is appended to the path. Warning: there is no automatic search in the current directory: add "-I ." for this. -where Print camlp5 library directory name and exit. -nolib No automatic search for objects files in camlp5 library directory. object-file The file is loaded in camlp5 core. OTHER OPTIONS
The others options are: file Treat file as an interface file if it ends with .mli and as an implementation file if it ends with .ml. -intf file Treat file as an interface file, whatever its extension. -impl file Treat file as an implementation file, whatever its extension. -unsafe Generate unsafe accesses to arrays and strings. -noassert Do not compile assertion checks. -verbose More verbose in parsing errors. -QD file Dump in file in case of syntax error in the result of a quotation expansion. -o out-file Print the result on out-file instead of standard output. File is opened with open_out_bin (see OCaml library Pervasives). -v Print the version number and exit. -help Print the available options and exit. This print includes the options possibly added by the loaded object files. The others options can be extended by loaded object files. The provided files add the following options: -l line-length Added by pr_o.cmo and pr_r.cmo: set the line length (default 78). -sep string Added by pr_o.cmo and pr_r.cmo: print this string between phrases instead of comments. -no_ss Added by pr_o.cmo: do not print double semicolons -D ident Added by pa_macro.cmo: define the ident. -U ident Added by pa_macro.cmo: undefine the ident. PROVIDED FILES
These files are installed in the directory /usr/lib/ocaml/camlp5. Parsing files: pa_r.cmo: revised syntax pa_rp.cmo: streams and parsers pa_lexer.cmo: lexers pa_o.cmo: normal syntax pa_op.cmo: streams and parsers pa_oop.cmo: streams and parsers (without code optimization) pa_scheme.cmo: scheme syntax pa_extend.cmo: syntax extension for grammars pa_extfold.cmo: extension of pa_extend with FOLD0 and FOLD1 pa_extfun.cmo: syntax extension for extensible functions pa_extprint.cmo: syntax extensions for extensible printers pa_pprintf.cmo: syntax extension for pprintf statement pa_fstream.cmo: syntax extension for functional streams pa_macro.cmo: add macros (ifdef, define) like in C pa_lefteval.cmo: left-to-right evaluation of parameters pa_pragma.cmo: directive #pragma Printing files: pr_r.cmo: revised syntax without objects and labels pr_ro.cmo: revised syntax for objects and labels pr_rp.cmo: try to rebuild streams and parsers syntax pr_o.cmo: normal syntax pr_op.cmo: try to rebuild streams and parsers syntax pr_scheme.cmo: Scheme syntax pr_schemep.cmo: try to rebuild streams and parsers syntax pr_extend.cmo: try to rebuild EXTEND statements pr_extfun.cmo: try to rebuild extfun statements pr_extprint.cmo: try to rebuild EXTEND_PRINTER statements pr_dump.cmo: dump syntax tree for ocaml compiler pr_depend.cmo: file dependencies pr_null.cmo: no output Quotation expanders: q_MLast.cmo: syntax tree nodes (in revised syntax) q_ast.cmo: syntax tree nodes in user full syntax q_phony.cmo: keeping quotations for pretty printing The command camlp5o is a shortcut for: camlp5 pa_o.cmo pa_op.cmo pr_dump.cmo The command camlp5r is a shortcut for: camlp5 pa_r.cmo pa_rp.cmo pr_dump.cmo The command camlp5sch is a shortcut for: camlp5 pa_scheme.cmo pr_dump.cmo The file camlp5o.cma can be loaded in the toplevel to start camlp5 with OCaml syntax. The file camlp5r.cma can be loaded in the toplevel to start camlp5 with revised syntax. The file camlp5sch.cma can be loaded in the toplevel to start camlp5 with Scheme syntax. MKCAMLP5 mkcamlp5 and mkcamlp5.opt creates camlp5 executables with almost the same options than ocamlmktop. The version mkcamlp5.opt can create native code executables, faster but not extensible. For mkcamlp5, the interfaces to be visible must be explicitly added in the command line as ".cmi" files. For example, how to add the the OCaml module "str": mkcamlp5 -custom str.cmi str.cma -cclib -lstr -o camlp5str ENVIRONMENT VARIABLE
The following environment variable is also consulted: CAMLP5PARAM Set the grammars parsing algorithm parameters. This variable must be a sequence of parameter specifications. A parameter specifi- cation is a letter optionally followed by an = and a value. There are four possible parameters: b (backtrack) Set the backtrack algorithm as default. t (trace) Trace symbols (terminals and non-terminals) while parsing with backtracking. y (trace-stalling) In backtracking, trace the advance in the input stream (number of unfrozen tokens) and the possible stalling (number of tokens tests). l (maximum-stalling) Set the maximum stalling value. FILES
Library directory of camlp5 in the present installation: /usr/lib/ocaml/camlp5 SEE ALSO
Camlp5 - Reference Manual ocamlc(1), ocaml(1), ocamlmktop(1). AUTHOR
Daniel de Rauglaudre, INRIA Rocquencourt. INRIA
CAMLP5(1)
All times are GMT -4. The time now is 09:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy