Sponsored Content
Top Forums Shell Programming and Scripting How to filter only comments while reading a file including line break characters. Post 302418242 by kchinnam on Monday 3rd of May 2010 03:31:29 PM
Old 05-03-2010
I still get the space prefix chracter[s] on third line.. I used a TAB + spacebar on third line in my input.. Again trimming should work for any combination of space characters.

Code:
$> /usr/xpg4/bin/awk 'NF && $1 != "#"{sub("#.*","");sub(/^ */,"");print}' input.txt
one="1111111" 
two="22222222"
         three=333333333

 

10 More Discussions You Might Find Interesting

1. Programming

Reading special characters while converting sequential file to line sequential

We have to convert a sequential file to a 80 char line sequential file (HP UX platform).The sequential file contains special characters. which after conversion of the file to line sequential are getting coverted into "new line" or "tab" and file is getting distorted. Is there any way to read these... (2 Replies)
Discussion started by: Rajeshsu
2 Replies

2. Shell Programming and Scripting

Reading a path (including ref to shell variable) from file

Hi! 1. I have a parameter file containing path to log files. For this example both paths are the same, one is stated directly and the second using env variables. /oracle/admin/orcl/bdump/:atlas:trc:N ${ORACLE_BASE}/admin/${ORACLE_SID}/bdump/:${ORACLE_SID}:trc:N 2. I try to parse the path... (1 Reply)
Discussion started by: lojzev
1 Replies

3. Shell Programming and Scripting

Replacing characters in file with line break

Hi, Apologies if this has been asked before, but I searched and was not able to find an answer. It's probably a simple question to answer for those of you with some experience, though... I have a relatively long string where tokens are separated by the colon (':') character. Let's say the... (10 Replies)
Discussion started by: johnemb
10 Replies

4. UNIX for Dummies Questions & Answers

Reading a line including spaces

Hi All, I have a script that reads a file and echo it back to std out. Test.txt 1aaaaaaaaaaa . The script is ReadLine.sh #!/bin/ksh cat $1 | while read file do echo $file done I invoke the script as ReadLine.sh Test.txt The output that I get is (1 Reply)
Discussion started by: aksarben
1 Replies

5. Shell Programming and Scripting

Break line after last "/" if length > X characters

Hello. I am a french newbie in unix shell scripting (sorry if my english speaking is wrong). I have a file with path and filenames in it. I want to limit the number of characters on each line and break the line if necessary. But the "break" should occur after a slash caracter "/". Example of... (9 Replies)
Discussion started by: SportBilly
9 Replies

6. Shell Programming and Scripting

filter record from a file reading another file

Hi, I want to filter record from a file if the records in the second column matches the data in another file. I tried the below awk command but it filters the records in the filter file. I want the opposite, to include only the records in the filter file. I tried this: awk -F'|'... (8 Replies)
Discussion started by: gpaulose
8 Replies

7. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

8. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

9. UNIX for Dummies Questions & Answers

add a string to a file without line break

I searched and found "echo -n" and "printf" are solution for this, but they are not here: $ echo "hello" >> test $ cat test hello $ echo -n "world" >> test $ cat test hello world $ echo -n " seriously?" >> test $ cat test hello world seriously? This is not successful... (15 Replies)
Discussion started by: stunn3r
15 Replies

10. UNIX for Beginners Questions & Answers

Including Hash / in sed command filter

Hello All, I want to print data in between two lines in a file sample.txt through more or cat command on the screen. For that I am using below sed command to give the BEGIN and END text. Content of sample.txt server01:~ # cat /proc/mdstat Hello this is a text message 1 Hello this is a... (5 Replies)
Discussion started by: Xtreme
5 Replies
pr(1)								   User Commands							     pr(1)

NAME
pr - print files SYNOPSIS
/usr/bin/pr [ + page] [-column] [-adFmrt] [ -e [char] [gap]] [-h header] [ -i [char] [gap]] [-l lines] [ -n [char] [width]] [-o offset] [ -s [char]] [-w width] [-fp] [file...] /usr/xpg4/bin/pr [ + page] [-column | -c column] [-adFmrt] [ -e [char] [gap]] [-h header] [ -i [char] [gap]] [-l lines] [ -n [char] [width]] [-o offset] [ -s [char]] [-w width] [-fp] [file...] DESCRIPTION
The pr utility is a printing and pagination filter. If multiple input files are specified, each is read, formatted, and written to standard output. By default, the input is separated into 66-line pages, each with: o a 5-line header that includes the page number, date, time and the path name of the file o a 5-line trailer consisting of blank lines If standard output is associated with a terminal, diagnostic messages will be deferred until the pr utility has completed processing. When options specifying multi-column output are specified, output text columns will be of equal width; input lines that do not fit into a text column will be truncated. By default, text columns are separated with at least one blank character. OPTIONS
The following options are supported. In the following option descriptions, column, lines, offset, page, and width are positive decimal integers; gap is a non-negative decimal integer. Some of the option-arguments are optional, and some of the option-arguments cannot be specified as separate arguments from the preceding option letter. In particular, the -s option does not allow the option letter to be sep- arated from its argument, and the options -e, -i, and -n require that both arguments, if present, not be separated from the option letter. The following options are supported for both /usr/bin/pr and /usr/xpg4/bin/pr: +page Begins output at page number page of the formatted input. -column Produces multi-column output that is arranged in column columns (default is 1) and is written down each column in the order in which the text is received from the input file. This option should not be used with -m. The -e and -i options will be assumed for multiple text-column output. Whether or not text columns are produced with identical vertical lengths is unspecified, but a text column will never exceed the length of the page (see the -l option). When used with -t, use the minimum number of lines to write the output. -a Modifies the effect of the -column option so that the columns are filled across the page in a round-robin order (for example, when column is 2, the first input line heads column 1, the second heads column 2, the third is the second line in column 1, and so forth). -d Produces output that is double-spaced; append an extra NEWLINE character following every NEWLINE character found in the input. -e[char][gap] Expands each input TAB character to the next greater column position specified by the formula n *gap+1, where n is an integer >0. If gap is 0 or is omitted, it defaults to 8. All TAB characters in the input will be expanded into the appropriate number of SPACE characters. If any non-digit character, char, is specified, it will be used as the input tab character. -f Uses a FORMFEED character for new pages, instead of the default behavior that uses a sequence of NEWLINE charac- ters. Pauses before beginning the first page if the standard output is associated with a terminal. -h header Uses the string header to replace the contents of the file operand in the page header. -l lines Overrides the 66-line default and reset the page length to lines. If lines is not greater than the sum of both the header and trailer depths (in lines), pr will suppress both the header and trailer, as if the -t option were in effect. -m Merges files. Standard output will be formatted so pr writes one line from each file specified by file, side by side into text columns of equal fixed widths, in terms of the number of column positions. Implementations support merging of at least nine files. -n[char][width] Provides width-digit line numbering (default for width is 5). The number will occupy the first width column posi- tions of each text column of default output or each line of -m output. If char (any non-digit character) is given, it will be appended to the line number to separate it from whatever follows (default for char is a TAB character). -o offset Each line of output will be preceded by offset <space>s. If the -o option is not specified, the default offset is 0. The space taken will be in addition to the output line width (see -w option below). -p Pauses before beginning each page if the standard output is directed to a terminal (pr will write an ALERT charac- ter to standard error and wait for a carriage-return character to be read on /dev/tty). -r Writes no diagnostic reports on failure to open files. -s [char] Separates text columns by the single character char instead of by the appropriate number of SPACE characters (default for char is the TAB character). -t Writes neither the five-line identifying header nor the five-line trailer usually supplied for each page. Quits writing after the last line of each file without spacing to the end of the page. -w width Sets the width of the line to width column positions for multiple text-column output only. If the -w option is not specified and the -s option is not specified, the default width is 72. If the -w option is not specified and the -s option is specified, the default width is 512. For single column output, input lines will not be truncated. /usr/bin/pr The following options are supported for /usr/bin/pr only: -F Folds the lines of the input file. When used in multi-column mode (with the -a or -m options), lines will be folded to fit the current column's width. Otherwise, they will be folded to fit the current line width (80 columns). -i[char][gap] In output, replaces SPACE characters with TAB characters wherever one or more adjacent SPACE characters reach col- umn positions gap+1, 2*gap+1, 3*gap+1, and so forth. If gap is 0 or is omitted, default TAB settings at every eighth column position are assumed. If any non-digit character, char, is specified, it will be used as the output TAB character. /usr/xpg4/bin/pr The following options are supported for /usr/xpg4/bin/pr only: -F Uses a FORMFEED character for new pages, instead of the default behavior that uses a sequence of NEWLINE charac- ters. -i[char][gap] In output, replaces multiple SPACE characters with TAB characters wherever two or more adjacent SPACE characters reach column positions gap+1, 2*gap+1, 3*gap+1, and so forth. If gap is 0 or is omitted, default TAB settings at every eighth column position are assumed. If any non-digit character, char, is specified, it will be used as the output TAB character. OPERANDS
The following operand is supported: file A path name of a file to be written. If no file operands are specified, or if a file operand is -, the standard input will be used. EXAMPLES
Example 1: Printing a numbered list of all files in the current directory example% ls -a | pr -n -h "Files in $(pwd)." Example 2: Printing files in columns This example prints file1 and file2 as a double-spaced, three-column listing headed by file list: example% pr -3d -h "file list" file1 file2 Example 3: Writing files with expanded column tabs The following example writes file1 on file2, expanding tabs to columns 10, 19, 28, ... example% pr -e9 -t <file1 >file2 ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of pr: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, LC_TIME, TZ, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: /usr/bin/pr +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ /usr/xpg4/bin/pr +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWxcu4 | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
expand(1), lp(1), attributes(5), environ(5), standards(5) SunOS 5.10 18 Mar 1997 pr(1)
All times are GMT -4. The time now is 02:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy