while read s; do
while read t; do
if echo "$t" | grep "${s#\#}"; then
read q; echo "$q"
fi
done <Input_file
done <reference_file
#tmp_4
trtyrghe
@tmp_4
8898rtyr2
#tmp_1
aewrgheheghe
@tmp_1
457awrerfa87
Rename variables to work easier, For example fh - fref, fh1 - fsrc, buf - ref, buf1 - src.
You need two loops - see my shell prototype.
You need strings, not char buffers, so after reading add '\0' to the end of string (you should remember the value from fgets - use auxiliary variable).
You need remove the first char from ref and src strings - use pointers (it's better to use two more variables).
Use strcmp from standard library to compare strings (find what header you need).
If there is a match, print src string and get and print the next string.
But before starting to code try to write the algorithm in words or (better) in pseudocode.
I believe you can to write a good program - you have the good start. If you would have some difficulties, try to write some simple programs at first - for example - the program which will be read one line from reference file, remove the first char, print it, and then print all lines from input file. Or the program which looks for constant string ("#tmp4") in the input file and print matching lines. Then improve it - it should print the matching and the next lines. And so on.
hi shamrock,
Kindly to point out if I'm wrong using of argc.
Based on what I understand, argc is using for command line arguments purpose.
Kindly correct me if I'm wrong coding.
I'm appreciate for any advice.
It ignores the first character in both buffers when comparing them.
I think it would have been simpler to write if (strcmp(ref+1, inp+1) == 0) { so the logic's in the strcmp instead of way high where you might forget it later.
The man command is your new friend, then.
$ man rewind
REWIND(3P) POSIX Programmer's Manual REWIND(3P)
PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux
implementation of this interface may differ (consult the corresponding
Linux manual page for details of Linux behavior), or the interface may
not be implemented on Linux.
NAME
rewind - reset the file position indicator in a stream
SYNOPSIS
#include <stdio.h>
void rewind(FILE *stream);
DESCRIPTION
The call:
rewind(stream)
shall be equivalent to:
(void) fseek(stream, 0L, SEEK_SET)