Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Answers to Frequently Asked Questions How to prevent sed command removing whole line? Post 302979353 by Don Cragun on Friday 12th of August 2016 05:19:09 PM
Old 08-12-2016
Hi beginner_99,
Note that the suggestions you have received work for your sample input (and any other input that has no comments or exactly one complete comment on each line). The suggestions will not work with the following "code":
Code:
/*
** Multi-line comment.
*/
/* Multiple comments... */ code; /* ... on one line. */

Are either of these limitations a problem for the real data you will be processing?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

removing parts of a line with SED

hi, i'm trying to erase all the characters after, and including, the first test test Output: test1 test2 test3 this is what I tried, but didn't work sed "s/*//" file > testfilename any suggestions? thanks, gammmaman (2 Replies)
Discussion started by: gammaman
2 Replies

2. Shell Programming and Scripting

removing a line containing a pattern in sed

i need to use sed to remove an entire line containing a pattern stored in a variable say $var1 this var1 will be a URL and will therefore contain slashes any help would be greatly appreciated (1 Reply)
Discussion started by: Fire_Storm
1 Replies

3. Shell Programming and Scripting

Sed question (Removing a line of text)

I am working with bash on HP-UX server at school. As practice for scripting, I am trying to make a pretend server admin script that adds a user to the system, deletes a user from the system, and lists all users of the pretend system. I have accomplished this with a select loop. Adding users, and... (2 Replies)
Discussion started by: masterscout1977
2 Replies

4. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

5. UNIX for Dummies Questions & Answers

Removing end of line using SED

Hello Friends, How can I remove the last two values of this line using sed John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638:9/3/90:45900 The result should look like this: John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638 (3 Replies)
Discussion started by: humkhn
3 Replies

6. Shell Programming and Scripting

sed removing until end of line

All: Can somebody help me out with a sed command, which removes the the first occurance of ')' until the end of the line If I have the following input ... (5 Replies)
Discussion started by: BeefStu
5 Replies

7. UNIX for Dummies Questions & Answers

sed or awk - removing part of line?

hi all, I am having trouble finding the right string for this - I dont know whether to use awk or sed.. If I have a file with alot of names and phone numbers like this McGowan,Sean 978-934-4000 Kilcoyne,Kathleen 603-555-1212 Club603,The 617-505-1332 Boyle,William 301-444-1221 And... (11 Replies)
Discussion started by: alis
11 Replies

8. UNIX for Dummies Questions & Answers

sed command for removing symbols

Hi I am trying to remove all the symbols in a file (testfile1) and using the below command to do that. Its not working for me. Can you help me on what is wrong with below script? I want to retain only alphabets in a file and remove all the symbols like *:.+= etc sed 's/^.//g' testfile1 > testfile2 (4 Replies)
Discussion started by: sandeepcm
4 Replies

9. Shell Programming and Scripting

sed - Removing all characters from token to end of line

Hello. The token is any printable characters between 2 " . The token is unknown, but we know that it is between 2 " Tok 1 : "1234x567" Tok 2 : "A3b6+None" Tok 3 : "A3b6!1234=@" The ligne is : Line 1 : "9876xABCDE"Do you have any code fragments or data samples in your post Line 2 : ... (3 Replies)
Discussion started by: jcdole
3 Replies

10. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
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 04:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy