Sponsored Content
Top Forums Shell Programming and Scripting how to extract multiple strings from a line Post 302279340 by cfajohnson on Thursday 22nd of January 2009 12:46:46 PM
Old 01-22-2009
Quote:
Originally Posted by vin_eme
Hi

I have the following requirement. i have the following line from a log file

one : two : Three : four : five : six : seven : eight :nine :ten

Now can you pls help what i should do to get only the following output from the above line

two : five : six : seven : Eight

Code:
line="one : two : Three : four : five : six : seven : eight :nine :ten"
IFS=' :'
set -f
set -- $line
printf "%s : " $2 $5 $6 $7; echo $8

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grepping Multiple Strings on the Same Line 'Or'

I've got this command that I've been using to find strings on the same line, say I'm doing a search for name: find . -name "*" | xargs grep -i "Doe" | grep -i "John" > output.txt This gives me every line in a file that has John and Doe in it. I'm looking to add a OR operator for the second... (5 Replies)
Discussion started by: Rally_Point
5 Replies

2. Shell Programming and Scripting

How to extract multiple line in a paragraph? Please help.

Hi all, The following lines are taken from a long paragraph: Labels of output orbitals: RY* RY* RY* RY* RY* RY* 1\1\GINC-COMPUTE-1-3\SP\UB3LYP\6-31G\C2H5Cr1O1(1+,5)\LIUZHEN\19-Jan-20 10\0\\# ub3lyp/6-31G pop=(nbo,savenbo) gfprint\\E101GECP\\1,5\O,0,-1.7 ... (1 Reply)
Discussion started by: liuzhencc
1 Replies

3. Shell Programming and Scripting

Extract strings from multiple lines into one file -

input file Desired csv output gc_type, date/time, milli secs af, Mar 17 13:09:04 2011, 144.596 af, Mar 20 00:37:37 2011, 144.242 af, ar 20 21:30:59 2011, 108.518 Hi All, Any help in acheiving the above would be appreciated. I would like to parse through lines within one file and... (5 Replies)
Discussion started by: satish.vampire
5 Replies

4. Shell Programming and Scripting

Extract strings from multiple lines into one csv file

Hi all, Please go through my requirement. I have a log file in the location /opt/WebSphere61/AppServer/profiles/EMQbatchprofile/logs/EMQbatch This file contains the follwing pattern data <af type="tenured" id="42" timestamp="May 14 13:44:13 2011" intervalms="955.624"> <minimum... (8 Replies)
Discussion started by: satish.vampire
8 Replies

5. Shell Programming and Scripting

ksh: how to extract strings from each line based on a condition

Hi , I'm a newbie.Never worked on Unix before. I want a shell script to perform the following: I want to extract strings from each line ,based on the type of line(Nameline,Subline) and output it to another file.Below is a sample format. 2010-12-21 14:00"1"Nameline"Midterm"First Name:Jane ... (4 Replies)
Discussion started by: angie1234
4 Replies

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

7. Shell Programming and Scripting

awk extract strings matching multiple patterns

Hi, I wasn't quite sure how to title this one! Here goes: I have some already partially parsed log files, which I now need to extract info from. Because of the way they are originally and the fact they have been partially processed already, I can't make any assumptions on the number of... (8 Replies)
Discussion started by: chrissycc
8 Replies

8. Shell Programming and Scripting

Extract multiple occurance of strings between 2 patterns

I need to extract multiple occurance strings between 2 different patterns in given line. For e.g. in below as input ------------------------------------------------------------------------------------- mike(hussey) AND mike(donald) AND mike(ryan) AND mike(johnson)... (8 Replies)
Discussion started by: sameermohite
8 Replies

9. Shell Programming and Scripting

USING sed to remove multiple strings/words from a line

Hi I use sed comnand to remove occurance of one workd from a line. However I need to removed occurance of dufferent words in ne line. Original-1 Hi this is the END of my begining Comand sed s/"END"/"start"/g Output-1 Hi this is the start of my beginig But I have more... (9 Replies)
Discussion started by: mnassiri
9 Replies

10. Shell Programming and Scripting

Extract multiple strings from line

Hello I have an output that has a string between quotes and another between square brackets on the same line. I need to extract these 2 strings Example line Device "nrst3a" attributes=(0x4) RAW SERIAL_NUMBER=SNL2 Output should look like nrst3a VD073AV1443BVW00083 I was trying with sed... (3 Replies)
Discussion started by: bombcan
3 Replies
indent(1)						      General Commands Manual							 indent(1)

Name
       indent - indent and format C program source

Syntax
       indent input [output] [flags]

Description
       The command is intended primarily as a C program formatter.  Specifically, indents code lines, aligns comments, inserts spaces around oper-
       ators where necessary and breaks up declaration lists as in ``int a,b,c;''.

       The command does not break up long statements to make them fit within the maximum line length, but it does flag lines that  are	too  long.
       Lines  are broken so that each statement starts a new line, and braces appear alone on a line.  Also, an attempt is made to line up identi-
       fiers in declarations.

       The flags that can be specified follow. They can appear before or after the file names.	If the output file is omitted, the formatted  file
       is  written back into input and a ``backup'' copy of input is written in the current directory.	If input is named ``/blah/blah/file'', the
       backup file is named ``.Bfile''.  If output is specified, checks to make sure it is different from input.

Options
       The following options are used to control the formatting style imposed by

       -lnnn	   Determines maximum length of output line.  The default is 75.

       -cnnn	   Determines column in which comments start.  The default is 33.

       -cdnnn	   Determines column in which comments on declarations start.  The default is for these comments to start in the  same	column	as
		   other comments.

       -innn	   Determines number of spaces for one indentation level.  The default is 4.

       -dj,-ndj    Causes declarations to be left justified.  -ndj causes them to be indented the same as code.  The default is -ndj.

       -v,-nv	   -v  turns  on  ``verbose''  mode, -nv turns it off.	When in verbose mode, reports when it splits one line of input into two or
		   more lines of output, and it gives some size statistics at completion.  The default is -nv.

       -bc,-nbc    Forces newline after each comma in a declaration.  -nbc turns off this option.  The default is -bc.

       -dnnn	   Controls the placement of comments which are not to the right of code.  Specifying -d2 means that such comments are placed  two
		   indentation	levels	to  the  left of code.	The default -d0 lines up these comments with the code.	See the section on comment
		   indentation below.

       -br,-bl	   Specifying -bl causes complex statements to be lined up in a space order.  For example,
		      if (...)
		      {
			  code
		      }
		   Specifying -br (the default) makes them look like this:
		      if (...) {
			  code
		      }

       You may set up your own ``profile'' of defaults to by creating the file ``.indent.pro'' in your	login  directory  and  including  whatever
       switches  you  like.  If is run and a profile file exists, then it is read to set up the program's defaults.  Switches on the command line,
       though, always override profile switches.  The profile file must be a single line of not more than 127 characters.  The switches should	be
       separated on the line by spaces or tabs.

       Multiline expressions

       The  command  does not break up complicated expressions that extend over multiple lines.  However, it usually indents such expressions that
       have already been broken up correctly.  Such an expression might look like the following:
       x =
	       (
		   (Arbitrary parenthesized expression)
		   +
		   (
		       (Parenthesized expression)
		       *
		       (Parenthesized expression)
		   )
	       );

       Comments

       The command recognizes the following four kinds of comments:

       1)  straight text

       2)  ``box'' comments

       3)  UNIX-style comments

       4)  comments that should be passed through unchanged

       The comments are interpreted as follows:

       ``Box'' comments    The command assumes that any comment with a dash immediately after the start of comment (i.e.  ``/*-'')  is	a  comment
			   surrounded by a box of stars.  Each line of such a comment is left unchanged, except that the first non-blank character
			   of each successive line is lined up with the beginning slash of the first line.  Box comments are indented (see below).

       ``Unix-style'' comments
			   This is the type of section header which is used extensively in the UNIX  system  source.   If  the	start  of  comment
			   (``/*'') appears on a line by itself, assumes that it is a UNIX-style comment.  These are treated similarly to box com-
			   ments, except the first non-blank character on each line is lined up with the `*' of the ``/*''.

       Unchanged comments  Any comment which starts in column 1 is left completely unchanged.  This is intended primarily for documentation header
			   pages.  The check for unchanged comments is made before the check for UNIX-style comments.

       Straight text	   All	other  comments are treated as straight text.  Indent fits as many words (separated by blanks, tabs, or new lines)
			   on a line as possible.  Straight text comments are indented.

       Comment indentation

       Box, UNIX-style, and straight text comments may be indented.  If a comment is on a line with code it is started in the ``comment  column'',
       which is set by the -cnnn command line parameter.  Otherwise, the comment is started at nnn indentation levels less than where code is cur-
       rently being placed, where nnn is specified by the -dnnn command line parameter.  (Indented comments is never be placed in column  1.)	If
       the code on a line extends past the comment column, the comment is moved to the next line.

Restrictions
       Does not know how to format ``long'' declarations.

Diagnostics
       Diagnostic error messages, mostly to tell that a text line has been broken or is too long for the output line.

Files
       .indent.pro    profile file

																	 indent(1)
All times are GMT -4. The time now is 08:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy