Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Comparing to specific line in file bash script Post 302732115 by Don Cragun on Friday 16th of November 2012 03:54:57 PM
Old 11-16-2012
Here is a bash (or ksh) script that will do what you want entirely in shell and using awk:
Code:
x=${1:-2222}
odd=1
while read data
do      if [ $odd = 1 ] && [ "x$x" = "x${data#????}" ]
        then    echo match found in "$data"
        fi
        odd=$((1 - odd))
done < input

awk -v x="$x" 'NR%2{if(x==substr($0,5)) printf("match found in %s\n",$0)}' input

The first line in this script uses the 1st argument to your script as the value to match, but defaults to "2222" if the 1st argument is missing or is an empty string.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A script that read specific fileds from the 7th line in a file

Dear All, I need a unix script that will read the 7th line and especially these fileds from a file Mo speed 16, Mt speed 15 every 15 minutes starting from 00:00 to 23:45 on daily basis and put the result in a txt file and name it MT_MO_20090225.txt, please also note that the system date format... (2 Replies)
Discussion started by: samura
2 Replies

2. Shell Programming and Scripting

How to read the value from a specific line and column BASH

Hi All, I have the same problem as the one posted in https://www.unix.com/shell-programming-scripting/96097-how-read-value-specific-line-column-csh-variable.html but I'm using bash. Can anyone tell me how I have to modify the code to make it bash compatible? eval `awk 'NR==3{print "set... (5 Replies)
Discussion started by: f_o_555
5 Replies

3. Shell Programming and Scripting

Korn/bash Script to monitor a file a check for specific data

Hi, Im trying to write this script but im stuck on it, basicaly what i want to do is to write a code to verify a log file ( apache log file for example ) and for each new line with specific data , then, output this new line for another file: full ex: output of the server.log is (... (4 Replies)
Discussion started by: Thales.Claro
4 Replies

4. UNIX for Dummies Questions & Answers

Comparing a number in a text file with a specific value

My project is to get a temperature reading from a refridgerator every 2 minutes and check to see if the door has been left open. I don't yet have the mastery of Linux, being a complete noob, but I reckon I need a text file with the latest temperature reading in it. This I've managed to do by... (2 Replies)
Discussion started by: Fitch
2 Replies

5. Shell Programming and Scripting

script for inserting line at specific place in file

I use zentyal for my server admin, which is great but zentyal auto-generates config file on boot and hence overwrites any changes made directly to config files. In order to allow multiple user access to a MS ACCESS database, I need to customise the smb.conf file and add the following line to the... (9 Replies)
Discussion started by: barrydocks
9 Replies

6. Shell Programming and Scripting

Bash - Appending to specific line in file

I'm working on a personal project, a multiplication quiz script for my kids. In it, the user's performance will be recorded and written to a file. After they've played it a little while, it will start to focus more on the ones that give them the most trouble-- that take a long time to answer or... (4 Replies)
Discussion started by: treesloth
4 Replies

7. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

8. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

9. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

10. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies
DIFF3(1)							     GNU Tools								  DIFF3(1)

NAME
diff3 - find differences between three files SYNOPSIS
diff3 [options] mine older yours DESCRIPTION
The diff3 command compares three files and outputs descriptions of their differences. The files to compare are mine, older, and yours. At most one of these three file names may be -, which tells diff3 to read the standard input for that file. Options Below is a summary of all of the options that GNU diff3 accepts. Multiple single letter options (unless they take an argument) can be com- bined into a single command line argument. -a Treat all files as text and compare them line-by-line, even if they do not appear to be text. -A Incorporate all changes from older to yours into mine, surrounding all conflicts with bracket lines. -B Old behavior of -A. Shows non-conflicts. -e Generate an ed script that incorporates all the changes from older to yours into mine. -E Like -e, except bracket lines from overlapping changes' first and third files. With -e, an overlapping change looks like this: <<<<<<< mine lines from mine ======= lines from yours >>>>>>> yours --ed Generate an ed script that incorporates all the changes from older to yours into mine. --easy-only Like -e, except output only the nonoverlapping changes. -i Generate w and q commands at the end of the ed script for System V compatibility. This option must be combined with one of the -AeExX3 options, and may not be combined with -m. --initial-tab Output a tab rather than two spaces before the text of a line in normal format. This causes the alignment of tabs in the line to look normal. -L label --label=label Use the label label for the brackets output by the -A, -E and -X options. This option may be given up to three times, one for each input file. The default labels are the names of the input files. Thus diff3 -L X -L Y -L Z -m A B C acts like diff3 -m A B C , except that the output looks like it came from files named X, Y and Z rather than from files named A, B and C. -m --merge Apply the edit script to the first file and send the result to standard output. Unlike piping the output from diff3 to ed, this works even for binary files and incomplete lines. -A is assumed if no edit script option is specified. --overlap-only Like -e, except output only the overlapping changes. --show-all Incorporate all unmerged changes from older to yours into mine, surrounding all overlapping changes with bracket lines. --show-overlap Like -e, except bracket lines from overlapping changes' first and third files. -T Output a tab rather than two spaces before the text of a line in normal format. This causes the alignment of tabs in the line to look normal. --text Treat all files as text and compare them line-by-line, even if they do not appear to be text. -v --version Output the version number of diff3. -x Like -e, except output only the overlapping changes. -X Like -E, except output only the overlapping changes. In other words, like -x, except bracket changes as in -E. -3 Like -e, except output only the nonoverlapping changes. SEE ALSO
cmp(1), comm(1), diff(1), ed(1), patch(1), sdiff(1). DIAGNOSTICS
An exit status of 0 means diff3 was successful, 1 means some conflicts were found, and 2 means trouble. GNU Tools 22sep1993 DIFF3(1)
All times are GMT -4. The time now is 12:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy