Sponsored Content
Full Discussion: Looking into file !
Top Forums Shell Programming and Scripting Looking into file ! Post 302138888 by drl on Wednesday 3rd of October 2007 05:12:43 PM
Old 10-03-2007
Hi.

This script creates another script. The new script uses sed, so it is quite fast, and the entire process is data-driven by the lookup file:
Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate creation of sed script with awk.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions used in this script displayed with local utility "version")"
version bash awk sed

echo

echo " Input file of lookup tokens:"
cat -tv data1

./a1 data1 > script
chmod +x script

echo
echo " This is the created sed script:"
cat -n script

echo
echo " Results of running script:"
./script data2

exit 0

You notice that there is an "a1" script. It's in awk, because awk facilitates handling text fields. However, the quoting is a bit complicated:
Code:
#!/usr/bin/awk -f

# @(#) a1       Demonstrate creation of sed script from lookup file.

echo

BEGIN { print "sed \\" }
        { print "-e 's/" $1 " /" $1$2 " /' \\" }
END     { print " data2" }

When s1 runs, it then produces:
Code:
% ./s1

(Versions used in this script displayed with local utility version)
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
GNU Awk 3.1.4
GNU sed version 4.1.2

 Input file of lookup tokens:
6589 7879
8787 0909
4343 4576

 This is the created sed script:
     1  sed \
     2  -e 's/6589 /65897879 /' \
     3  -e 's/8787 /87870909 /' \
     4  -e 's/4343 /43434576 /' \
     5   data2

 Results of running script:
6767879898009965897879 65656576687878
7887576576757687870909 88787878756446
3232476568769843434576 42341242542345

Best wishes ... cheers, drl
 

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. 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
SHTOOLIZE.TMP(1)					      GNU Portable Shell Tool						  SHTOOLIZE.TMP(1)

NAME
shtoolize - Build individual GNU shtool scripts VERSION
GNU shtool 2.0.8 (18-Jul-2008) SYNOPSIS
shtoolize [-h] [-v] [-q] [-o script] module [ module ... ] DESCRIPTION
The shtoolize program builds individual GNU shtool scripts (written to the default output file "shtool" or to the specified script) out of one or more shtool ingredient modules. Available modules are: echo Print string with optional construct expansion mdate Pretty-print modification time of a file or dir table Pretty print a field-separated list as a table prop Display progress with a running propeller move Move files with simultan substitution install Install a program, script or datafile mkdir Make one or more directories mkln Make link with calculation of relative paths mkshadow Make a shadow tree fixperm Fix file permissions inside a source tree rotate Rotate a logfile tarball Roll distribution tarballs subst Apply sed(1) substitution operations platform Platform identification utility arx Extended archive command slo Separate linker options by library class scpp Sharing C Pre-Processor version Generate and maintain a version information file path Deal with program paths Additionally there is a pseudo-module ``"all"'' which can be used as a short-hand for ``"echo mdate table prop move install mkdir mkln mkshadow fixperm platform arx slo scpp version path"'', i.e. to build a shtool script with all modules in the standard order. An installed shtool is usually built this way via ``"shtoolize -o shtool all"''. Use the shtoolize program to build individual shtool scripts in case you want a smaller sized script and you don't need all of the available shtool functionality. For instance for the classical Autoconf based free software package a "shtool" script build via ``"shtoolize -o shtool install mkdir"'' might be sufficient. OPTIONS
The following command line options exist: -h Displays a short help page describing the usage of shtoolize. -v Displays the version number of shtoolize/shtool. -q Displays no processing information. -o script Writes the output to file script instead to file ``"shtool"''. EXAMPLE
The typical free software package which is based on GNU libtool and GNU shtool one uses a "Makefile" entry like the following: # Makefile entry for upgrading GNU tools upgrade-tools: libtoolize -f -c shtoolize -q all This upgrades the three files "ltmain.sh", "ltconfig" and "shtool" in the current source tree to the latest versions. SEE ALSO
shtool(1). AUTHOR
Ralf S. Engelschall rse@engelschall.com www.engelschall.com 18-Jul-2008 shtool 2.0.8 SHTOOLIZE.TMP(1)
All times are GMT -4. The time now is 10:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy