Sponsored Content
Top Forums Shell Programming and Scripting Change indentation in scripts Post 302780053 by bakunin on Wednesday 13th of March 2013 05:17:05 PM
Old 03-13-2013
chubler_XL is correct. I use 5 spaces indentation and if a line doesn't fit within 80 characters i think hard if it is really good to do it that way (in most cases it isn't and it is the rare exception if it is).

To reduce the indentation in sed (replace "<b>" and "<t>" with literal blanks/tabs):

Code:
sed ':search
     /^<b><b>/ {
                 s/^\([<b>]*\)\(<b><b>\)\([^<b>]\)/\1;\3/
                 b search
              }

     :replace
     /^;/     {
                 s/^\(;*\);/\1<b>/
                 b replace
              }' /path/to/input


You can easily adapt this to other levels of indentation by modifying the parts marked bold to contain more or less blanks. Note that lines have to start leftmost - no effort is made to deal with lines not starting at character position 1.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find all scripts to change DNS name??

hi, we are going for a new unix box and the ip and DNS name has to be changed in all the scripts, where ever it is hard coded. i was trying the below mentioned command to list all such scripts where the ip/dns name is hard coded: find / -type f -print | xargs grep -l "ip address" >>... (0 Replies)
Discussion started by: Bhups
0 Replies

2. Programming

A question of indentation

Hi, Using GNU indent(1) I tried to indent a C source file which has no indentation (all lines start at column 1). The result I am trying to achieve, should look like this with the exception that only tabs are used for indentation (no spaces). Unfortunately, I couldn't find the appropriate... (1 Reply)
Discussion started by: Michael Iatrou
1 Replies

3. Shell Programming and Scripting

How to make the same change in multiple shell scripts?

I would like to make the same change in multiple shell script files and would like to know if anyone can be of some help? I would appreciate it. (4 Replies)
Discussion started by: rdakhan
4 Replies

4. Shell Programming and Scripting

Scripts fails if you change its code during the execution.

So a script is working properly (tested many times) , then you add a new fine piece of code ,finaly its fails generally with a syntax error at the last line of the script. :confused:... does anybody why this happens? >uname -a HP-UX test... (4 Replies)
Discussion started by: Klashxx
4 Replies

5. Shell Programming and Scripting

Indentation help

Hi I have coded 300 line script.Its not indented properly.i am not good at indentation. I would appreciate your help on this. i want to use a 4 space indentataion.Hence if i "set tabstop=4" and use tabs for coding and if some one else open this script in their system it looks unindented since... (11 Replies)
Discussion started by: pinnacle
11 Replies

6. UNIX for Advanced & Expert Users

What files or programs have the ability to change your default network scripts and config

What files or programs have the ability to change your default network scripts and config files? All 3 of these very important files got changed on their own. /etc/sysconfig/network-scripts/ifcfg-wlan0 /etc/sysconfig/networking/devices/ifcfg-wlan0... (4 Replies)
Discussion started by: cokedude
4 Replies

7. Shell Programming and Scripting

Can anybody change this into Linux shell scripts?

@echo off SET "p0=%~0" SET "p1=%~1" SET "p2=%~2" SET "p3=%~3" SET "p4=%~4" SET "p5=%~5" SET "p6=%~6" SET "p7=%~7" SET "p8=%~8" SET "p9=%~9" SHIFT SET "p10=%~9" SHIFT SET "p11=%~9" SET "zip_path=D:\OraOutput\interco\%p10%" echo Program... (5 Replies)
Discussion started by: monisha
5 Replies

8. UNIX for Dummies Questions & Answers

Indentation using awk

I need to write an awk program who does this http://i.stack.imgur.com/yzSqB.jpg I'd be very grateful for any help, Thanks a lot (1 Reply)
Discussion started by: guy9050
1 Replies

9. Homework & Coursework Questions

Indentation using awk

1. The problem statement, all variables and given/known data: I need to write an awk program who does this (sorry its too big) http://i.stack.imgur.com/yzSqB.jpg 2. Relevant commands, code, scripts, algorithms: .. 3. The attempts at a solution (include all code and scripts): declaring a... (2 Replies)
Discussion started by: guy9050
2 Replies

10. UNIX for Beginners Questions & Answers

Indentation for Lists in html

An writing some html instructions to have text beside an image. The image is located on the left and I want the tect to appear on the right side of the image. The text includes a list. The problem is that the list boxes and not shifted. The text within the list align on the left with the... (20 Replies)
Discussion started by: kristinu
20 Replies
Indent reads a C program in, rearranges the layout, and outputs a
new C program that will compile to the same executable binary  as
the original one.  The difference between the input and output is
that the output is in a standard layout  determined  by  a  large
number	of options.  For most of the options there are two choic-
es, one that enables it and one that disables it.  If  indent  is
called	with  no  file files, it operates as a filter.	If called
with one file name, that file is reformatted and the  result  re-
places the original file.  A backup is created, however, with the
suffix .BAK.  If it is called with two file names, the first  one
is  the  input	file and the second one is the output file.  Only
one file can be reformatted at a time (e.g., one cannot call  in-
dent  with *.c as argument; this is an error and will not work.).
Many options are available.  If you want to format a  program  to
the  official  MINIX  format, use pretty, which calls indent with
the proper options and then postprocesses the  output.	 The  op-
tions listed below control the formatting style.

OPTION
: -bad, -nbad If -bad is specified, a blank line is forced after every block of declarations. Default: -nbad. OPTION
: -bap, -nbap If -bap is specified, a blank line is forced after every procedure body. Default: -nbap. OPTION
: -bbb, -nbbb If -bbb is specified, a blank line is forced before every block comment. Default: -nbbb. OPTION
: -bc, -nbc If -bc is specified, then a newline is forced after each comma in a declaration. -nbc turns off this option. The default is -nbc. OPTION
: -bl, -br Specifying -bl lines up compound statements like this: if (...) { code } Specifying -br (the default) makes them look like this: if (...) { code } OPTION
: -cn The column in which comments on code start. The de- fault is 33. OPTION
: -cdn The column in which comments on declarations start. The default is for these comments to start in the same column as those on code. OPTION
: -cdb, -ncdb Enables (disables) the placement of comment delimiters on blank lines. With this option enabled, comments look like this: /* * this is a comment */ Rather than like this: /* this is a comment */ This only affects block comments, not comments to the right of code. The default is -cdb. OPTION
: -ce, -nce Enables (disables) forcing elses to cuddle up to the immediately preceding }. The default is -ce. OPTION
: -cin Sets the continuation indent to be n. Continuation lines will be indented that far from the beginning of the first line of the statement. Parenthesized expressions have extra in- dentation added to indicate the nesting, unless -lp is in effect. -ci defaults to the same value as -i. OPTION
: -clin Causes case labels to be indented n tab stops to the right of the containing switch statement. -cli0.5 causes case labels to be indented half a tab stop. The default is -cli0. (This is the only option that takes a fractional argu- ment.) OPTION
: -dn Controls the placement of comments which are not to the right of code. Specifying -d1 means that such comments are placed one indentation level to the left of code. The default -d0 lines up these comments with the code. See the section on comment indentation below. OPTION
: -din Specifies the indentation, in character positions, from a declaration keyword to the following identifier. The de- fault is -di16. OPTION
: -dj, -ndj -dj left justifies declarations. -ndj indents declarations the same as code. The default is -ndj. OPTION
: -ei, -nei Enables (disables) special else-if processing. If enabled, ifs following elses will have the same indentation as the preceding if statement. The default is -ei. OPTION
: -fc1, -nfc1 Enables (disables) the formatting of comments that start in column 1. Often, comments whose leading / is in column 1 have been carefully hand formatted by the programmer. In such cases, -nfc1 should be used. The default is -fc1. OPTION
: -in The number of spaces for one indentation level. The default is 8. OPTION
: -ip, -nip Enables (disables) the indentation of parameter declarations from the left margin. The default is -ip. OPTION
: -ln Maximum length of an output line. The default is 78. OPTION
: -lp, -nlp Lines up code surrounded by parenthesis in con- tinuation lines. If a line has a left paren which is not closed on that line, then continuation lines will be lined up to start at the character position just after the left paren. OPTION
: -npro Causes the profile files, .indent.pro in both the current directory and the user's home directory to be ignored. OPTION
: -pcs, -npcs If true (-pcs) all procedure calls will have a space inserted between the name and the (. The default is -npcs. OPTION
: -ps, -nps If true (-ps) the pointer following operator -> will be surrounded by spaces on either side. The default is -nps. OPTION
: -psl, -npsl If true (-psl) the names of procedures being defined are placed in column 1 - their types, if any, will be left on the previous lines. The default is -psl. OPTION
: -sc, -nsc Enables (disables) the placement of asterisks (*) at the left edge of all comments. The default is -sc. OPTION
: -sob, -nsob If -sob is specified, indent will swallow op- tional blank lines. You can use this to get rid of blank lines after declarations. The default is -nsob. OPTION
: -st Causes indent to take its input from stdin, and put its output to stdout. OPTION
: -Ttypename Adds typename to the list of type keywords. Names accumulate: -T can be specified more than once. You need to specify all the typenames that appear in your program that are defined by #typedefs. Nothing will be harmed if you miss a few, but the program will not be formatted as nicely as it should. This sounds like a painful thing to have to do, but it is really a symptom of a problem in C: typedef causes a syntactic change in the language and indent cannot find all typedefs. OPTION
: -troff Causes indent to format the program for processing by troff. It will produce a fancy listing in much the same spir- it as vgrind. If the output file is not specified, the default is standard output, rather than formatting in place. OPTION
: -v, -nv The -v flag turns on verbose mode; -nv turns it off. When in verbose mode, indent reports when it splits one line of input into two or more lines of output, and gives some size statistics at completion. The default is -nv. You may set up your own profile of defaults to indent by creating a file called .indent.pro in either your login directory and/or the cur- rent directory and including whatever switches you like. Switch- es in .indent.pro in the current directory override those in your login directory (with the exception of -T type definitions, which just accumulate). If indent is run and a profile file exists, then it is read to set up the program's defaults. The switches should be separated by spaces, tabs or newlines. Switches on the command line, however, override profile switches. Indent assumes that any comment with a dash or star immediately after the start of comment (that is, /*- or /**) is a comment surrounded by a box of stars. Each line of such a comment is left unchanged, except that its indentation may be adjusted to account for the change in indentation of the first line of the comment. All other comments are treated as straight text. Indent fits as many words (sepa- rated by blanks, tabs, or newlines) on a line as possible. Blank lines break paragraphs. If a comment is on a line with code it is started in the comment column, which is set by the -cn command line parameter. Otherwise, the comment is started at n indenta- tion levels less than where code is currently being placed, where n is specified by the -dn command line parameter. If the code on a line extends past the comment column, the comment starts fur- ther to the right, and the right margin may be automatically ex- tended in extreme cases. In general, indent leaves preprocessor lines alone. The only reformatting that it will do is to straighten up trailing comments. It leaves embedded comments alone. Conditional compilation (#ifdef...#endif) is recognized and indent attempts to correctly compensate for the syntactic pe- culiarities introduced. Indent understands a substantial amount about the syntax of C, but it has a forgiving parser. It at- tempts to cope with the usual sorts of incomplete and misformed syntax. In particular, the use of macros like: #define forever for(;;) is handled properly.
All times are GMT -4. The time now is 09:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy