Sponsored Content
Full Discussion: Aligning a file
Top Forums Shell Programming and Scripting Aligning a file Post 302914156 by drl on Friday 22nd of August 2014 07:51:17 AM
Old 08-22-2014
Hi.

The general alignment program align provides a feature for processing only lines on which patterns match:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate align text for matched lines, align.
# For align code, see:
# http://freecode.com/projects/align

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C align

FILE=${1-data1}

pl " Input data file $FILE:"
cat $FILE

pl " Results, align text only in lines in which \"==>\" appears:"
align -e "/==>/" $FILE

pl " Results, with a wider gutter:"
align -g 5 -e "/==>/" $FILE

exit 0

producing:
Code:
$ ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian 5.0.8 (lenny, workstation) 
bash GNU bash 3.2.39
align 1.7.0

-----
 Input data file data1:
abc
qwert
qwer
afweferf
wdfwefwe ==> kjhjkwdd
mnmn ==> jkjkjwekj
poiu ==> lklklke
tytyutut ==> olkjmnsmn
This text need not be aligned.

-----
 Results, align text only in lines in which "==>" appears:
abc
qwert
qwer
afweferf
wdfwefwe ==> kjhjkwdd
mnmn     ==> jkjkjwekj
poiu     ==> lklklke
tytyutut ==> olkjmnsmn
This text need not be aligned.

-----
 Results, with a wider gutter:
abc
qwert
qwer
afweferf
wdfwefwe     ==>     kjhjkwdd
mnmn         ==>     jkjkjwekj
poiu         ==>     lklklke
tytyutut     ==>     olkjmnsmn
This text need not be aligned.

The code for align can be obtained from the URL noted in the first part of the script.

Best wishes ... cheers, drl

Last edited by drl; 08-24-2014 at 02:27 PM.. Reason: Edit 1 - correct minor typo.
These 2 Users Gave Thanks to drl For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Aligning Characters in Bash/Beautiful Screens

Howdy, Supposing I want to output the following code to the screen in a bash script, this works fine until you use variables as below, because the variable could be of any length, meaning the screen output for line 2 will have the ultimate # out of alignment. Is there a simple way round this?... (1 Reply)
Discussion started by: de_la_espada
1 Replies

2. Programming

Aligning for boundary conditions

Hi, I have tcp/ip client server programs which will communicate through reqest,reply c-structures. As the sizeof(struct) may give different value between client and server programs, how do i align properly for boundary conditions. Could anybody please give some suggestion. Thanks in... (3 Replies)
Discussion started by: axes
3 Replies

3. Shell Programming and Scripting

Aligning text files by max field length

Hello, Is there anyway that I can align a pipe delimited text file by the maxium field length where the field is separated out by pipes for large text files with more than 100,000 rows? So, far I have searched other forums and google about aligning text files in unix and I have noticed that... (7 Replies)
Discussion started by: physalis2099
7 Replies

4. Shell Programming and Scripting

Aligning numbers in the second file based on first file

Hi All, I have two sets of files with names .dat and .txt. The number of files is really large more than 90000. The files have names like 1.dat, 2.dat,3.dat and so on where as txt files have names like 1.txt, 2.txt, 3.txt and so on The DAT and TXT files are equal in number. About 90000 each ... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

5. Shell Programming and Scripting

Aligning columns in a text file using Perl

Hi All, I am new to perl and was trying to write a simple program which will generate a text file as output.. now the output which i am getting is something like this.. ================================================================================================== Col1 ... (8 Replies)
Discussion started by: smarty86
8 Replies

6. UNIX for Dummies Questions & Answers

Help with Aligning the content of a txt file

Hello friends Please help me to display the content of a file in specific aligned manner. for ex. the content of the file may be >$TEST WELCOME HI HELLO UNIX SHELL SCRIPTING >$ I want to display the content like . TEST WELCOME HI HELLO ... (18 Replies)
Discussion started by: rajmohan146
18 Replies

7. Shell Programming and Scripting

Aligning output with null fields in shell script

Hello Gurus ! I have what probably amounts to a few simply changes to fix; however for the life of me I cannot seem to get it ti work. I need to align the output of my script (I am writing to a logfile)... here's the lines in my code: if then echo "NODE: $node" >> $logfile... (6 Replies)
Discussion started by: gvolpini
6 Replies

8. Shell Programming and Scripting

Aligning data

Hi Guys, How can you align data getting the UID, GID HOSTNAME in same column input: server1 uid=1010(faculty) gid=700(teacher) groups=700(teacher), 800(models) student:x:500:500:student:/home/student:/bin/bash server2 uid=1010(OSAD) gid=700(teacher) groups=700(teacher), 809(staff)... (5 Replies)
Discussion started by: invinzin21
5 Replies

9. Shell Programming and Scripting

Aligning Texts

is there any way to align my text so every column begins on the same line as the previous line? here's my command: printf "THEN ( ${SEARCHPATTB} = Hour = ${CALTOTB} ) %8s => %8s NOW ( ${SEARCHPATT} = Hour = ${CALTOT} ) %7s => %7s Reduced By: %7s -${RESULT}"\\n output i'm currently getting... (2 Replies)
Discussion started by: SkySmart
2 Replies

10. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies
MyBackground(1x)					   AfterStep X11 window manager 					  MyBackground(1x)

NAME
MyBackground - details how background is to be rendered CONFIGURATION OPTIONS
Align [type] it will align resulting image according to type. Possible values are : 1: - align to the right of the screen 2: - align to the bottom of the screen 3: - align to the bottom-right of the screen 0 or 4: - align to the center of the screen This option works only in conjunction with the following Pad option. Cut "geometry" will cut piece with specified geometry from the source image. MyBackground "background_name" background_option ~MyBackground Specifies the beginning of a background definition. The background can be referred to later by background_name. ~MyBackground ends a root background definition. Pad [type color] will pad image if it is smaller then screen with specified color. Possible type values are : 1: - pad horizontally and tile vertically 2: - pad vertically and tile horizontally 3: - pad both vertically and horizontally to make the image the size of the screen. Scale [geometry] scale image to specified geometry. If geometry is omitted the image will be scaled to the screen size. Tint color Use type "data" Specifies what to use as the root background. Possible type values are : 0: load image from the file. In that case "data" should specify filename. 1: Use MyStyle definition to fill root. In that case "data" should specify one of the MyStyle names defined in your look file. 2: Use external application to set root background. "data" should specify command line options to this external app. If you wish to use another application to display the root background, you need to set the "--with-imageloader" flag to use that application then recompile AfterStep.) Note: remaining Background options are valid only for type of 0 !!! The remaining options will perform transformations on the source image, in this order: Cut->Tint->Scale->Align->Pad. 3rd Berkeley Distribution AfterStep v.2.2.11 MyBackground(1x)
All times are GMT -4. The time now is 02:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy