Sponsored Content
Full Discussion: Looking into file !
Top Forums Shell Programming and Scripting Looking into file ! Post 302138899 by tomas on Wednesday 3rd of October 2007 06:15:14 PM
Old 10-03-2007
Quote:
Originally Posted by drl
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
I haven't seen anything like this before. Very cool. I will need to play with this. Smilie
 

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
IGNORE_USER_ABORT(3)							 1						      IGNORE_USER_ABORT(3)

ignore_user_abort - Set whether a client disconnect should abort script execution

SYNOPSIS
int ignore_user_abort ([string $value]) DESCRIPTION
Sets whether a client disconnect should cause a script to be aborted. When running PHP as a command line script, and the script's tty goes away without the script being terminated then the script will die the next time it tries to write anything, unless $value is set to TRUE PARAMETERS
o $value - If set, this function will set the ignore_user_abort ini setting to the given $value. If not, this function will only return the previous setting without changing it. RETURN VALUES
Returns the previous setting, as an integer. EXAMPLES
Example #1 A ignore_user_abort(3) example <?php // Ignore user aborts and allow the script // to run forever ignore_user_abort(true); set_time_limit(0); echo 'Testing connection handling in PHP'; // Run a pointless loop that sometime // hopefully will make us click away from // page or click the "Stop" button. while(1) { // Did the connection fail? if(connection_status() != CONNECTION_NORMAL) { break; } // Sleep for 10 seconds sleep(10); } // If this is reached, then the 'break' // was triggered from inside the while loop // So here we can log, or perform any other tasks // we need without actually being dependent on the // browser. ?> NOTES
PHP will not detect that the user has aborted the connection until an attempt is made to send information to the client. Simply using an echo statement does not guarantee that information is sent, see flush(3). SEE ALSO
connection_aborted(3), connection_status(3), Connection Handling for a complete description of connection handling in PHP. . PHP Documentation Group IGNORE_USER_ABORT(3)
All times are GMT -4. The time now is 05:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy