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
script(1)							   User Commands							 script(1)

NAME
script - make record of a terminal session SYNOPSIS
script [-a] [filename] DESCRIPTION
The script utility makes a record of everything printed on your screen. The record is written to filename. If no file name is given, the record is saved in the file typescript. See WARNINGS. The script command forks and creates a sub-shell, according to the value of $SHELL, and records the text from this session. The script ends when the forked shell exits or when Control-d is typed. OPTIONS
The following option is supported: -a Appends the session record to filename, rather than overwriting it. NOTES
script places everything that appears on the screen in filename, including prompts. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) WARNINGS
script can pose a security risk when used in directories that are writable by other users (for example, /tmp), especially when run by a privileged user, that is, root. Be sure that typescript is not a link before running script. SunOS 5.11 30 Jan 2004 script(1)
All times are GMT -4. The time now is 03:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy